You can track your your WhatsApp & Telegram users with UTM parameters, when they go from a web page to WhatsApp (or other messenger) via HighTouch short link.
To forward UTM-parameters from you webpage to HighTouch – copy and paste to your webpage following script:
Copy <script>
// Protect global scope
(function() {
// List of UTM parameters names
var utmParametersNames = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'utm_referrer'];
// Function extracts UTM parameters from window.location.search
// Returns array of URI-encoded parameters, can be replaced
function getUtmParameters() {
var utmParameters = [];
window.location.search.slice(1).split('&').forEach(function(parameter) {
var parameterParts = parameter.split('=');
var parameterName = parameterParts[0];
if (utmParametersNames.indexOf(parameterName) !== -1) {
utmParameters.push(parameter);
}
});
return utmParameters;
}
// Function adds UTM-parameters to all links lead to domain go.hightouch.ai
function addUTM() {
var utmParameters = getUtmParameters();
if (!utmParameters.length) {
return;
}
var links = document.querySelectorAll('a');
var processLink = function(link) {
var hostname;
if (typeof link.hostname !== 'undefined') {
hostname = link.hostname;
} else {
var hostnameMatch = link.href.match(/^https?\:\/\/([^:\/?#]*)/);
hostname = hostnameMatch && hostnameMatch[1];
}
if (hostname === 'go.hightouch.ai') {
var hrefParts = link.href.split('?');
var processedHref = hrefParts[0];
if (hrefParts.length > 1) {
var oldParameters = hrefParts[1].split('&');
var newParametersString = utmParameters.join('&');
oldParameters.forEach(function(parameter) {
var parameterParts = parameter.split('=');
var parameterName = parameterParts[0];
if (utmParametersNames.indexOf(parameterName) === -1) {
newParametersString += '&' + parameter;
}
});
processedHref += '?' + newParametersString;
} else {
processedHref += '?' + utmParameters.join('&');
}
link.href = processedHref;
}
};
links.forEach(processLink);
}
// Run addUTM only when document is ready.
// You can replace code below using jQuery.ready(addUTM) or something similar.
function documentReady() {
document.removeEventListener('DOMContentLoaded', documentReady);
window.removeEventListener('load', documentReady);
addUTM();
}
if (document.readyState === 'complete'
|| (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
setTimeout(addUTM, 1);
} else {
document.addEventListener('DOMContentLoaded', documentReady);
window.addEventListener('load', documentReady);
}
})();
</script>