Analytics, UTM parameters
How to use Google Analytics UTM in chatbots
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.
utm_medium= traffic type utm_source= traffic source (site) utm_campaign= advertising campaign utm_term= keywords utm_content= additional information utm_referrer= tag for Yandex Metrika
Example: https://go.eu.hightouch.ai/acfwKw?utmsource=landingpage
To forward UTM-parameters from you webpage to HighTouch – copy and paste to your webpage following script:
1
<script>
2
// Protect global scope
3
(function() {
4
5
// List of UTM parameters names
6
var utmParametersNames = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'utm_referrer'];
7
8
// Function extracts UTM parameters from window.location.search
9
// Returns array of URI-encoded parameters, can be replaced
10
function getUtmParameters() {
11
var utmParameters = [];
12
window.location.search.slice(1).split('&').forEach(function(parameter) {
13
var parameterParts = parameter.split('=');
14
var parameterName = parameterParts[0];
15
if (utmParametersNames.indexOf(parameterName) !== -1) {
16
utmParameters.push(parameter);
17
}
18
});
19
return utmParameters;
20
}
21
22
// Function adds UTM-parameters to all links lead to domain go.hightouch.ai
23
function addUTM() {
24
var utmParameters = getUtmParameters();
25
if (!utmParameters.length) {
26
return;
27
}
28
var links = document.querySelectorAll('a');
29
var processLink = function(link) {
30
var hostname;
31
if (typeof link.hostname !== 'undefined') {
32
hostname = link.hostname;
33
} else {
34
var hostnameMatch = link.href.match(/^https?\:\/\/([^:\/?#]*)/);
35
hostname = hostnameMatch && hostnameMatch[1];
36
}
37
if (hostname === 'go.hightouch.ai') {
38
var hrefParts = link.href.split('?');
39
var processedHref = hrefParts[0];
40
if (hrefParts.length > 1) {
41
var oldParameters = hrefParts[1].split('&');
42
var newParametersString = utmParameters.join('&');
43
oldParameters.forEach(function(parameter) {
44
var parameterParts = parameter.split('=');
45
var parameterName = parameterParts[0];
46
if (utmParametersNames.indexOf(parameterName) === -1) {
47
newParametersString += '&' + parameter;
48
}
49
});
50
processedHref += '?' + newParametersString;
51
} else {
52
processedHref += '?' + utmParameters.join('&');
53
}
54
link.href = processedHref;
55
}
56
};
57
links.forEach(processLink);
58
}
59
60
61
// Run addUTM only when document is ready.
62
// You can replace code below using jQuery.ready(addUTM) or something similar.
63
function documentReady() {
64
document.removeEventListener('DOMContentLoaded', documentReady);
65
window.removeEventListener('load', documentReady);
66
addUTM();
67
}
68
69
if (document.readyState === 'complete'
70
|| (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
71
setTimeout(addUTM, 1);
72
} else {
73
document.addEventListener('DOMContentLoaded', documentReady);
74
window.addEventListener('load', documentReady);
75
}
76
})();
77
</script>
Copied!
Copy link