blob: 4c0829d7cd4688700eae594036058cef330aab86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Monitor all download links in GA
var dlCnt = 0;
function GAizeDownloadLink(a) {
var url = a.href;
var x = url.indexOf("?");
if (x != -1) {
url = url.substr(0, x);
}
var url_test = url.match(/^https?:\/\/.+(\/rpms\/.*\.rpm|\/deb\/.*\.deb|\/single-binary\/Darwin\/.*\/q|\/archive\/.*\.tar\.gz|\/archive\/.*\.zip|\/windows\/.*\.exe)$/i);
if (url_test) {
console.log("Converting download link to be GA aware: " + url);
if (url_test.length > 1) {
var event_action = url_test[1];
} else {
var event_action = 'unknown_action';
}
a.event_action = event_action;
dlCnt = dlCnt + 1;
a.onclick = function() {
console.log("Sending GA event for link" + url);
var that = this;
gtag('event','perform download', { 'event_category': 'Downloads', 'event_label': 'Download ' + this.event_action , 'value': 1 });
setTimeout(function() {
location.href = that.href;
}, 500);
return false;
};
}
}
function GAizeTOCLink(l) {
l.onclick = function() {
url_test = l.href.match(/^https?:\/\/.+(#.*)$/i);
toc_name = url_test[1];
var that = this;
console.log("Sending GA event for toc link " + this.href);
gtag('event','navigate', { 'event_category': 'Navigation', 'event_label': 'go to ' + toc_name, 'value': 1 });
setTimeout(function() {
location.href = that.href;
}, 250);
return false;
};
}
window.onload = function() {
var anchors = document.getElementsByTagName('a');
for (i = 0; i < anchors.length; i++) {
GAizeDownloadLink(anchors[i]);
}
var toc_links = document.querySelectorAll('div.md-sidebar[data-md-component=toc] a.md-nav__link');
for (i = 0; i < toc_links.length; i++) {
GAizeTOCLink(toc_links[i]);
}
console.log("Converted " + dlCnt + " links to be GA aware");
}
|