This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscript.js
90 lines (74 loc) · 3.09 KB
/
script.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Set up Google analytics
*
* All configuration is done in the JSINFO.ga object initialized in
* action.php
*/
if (JSINFO.ga) {
if (JSINFO.ga.gtagId) {
/* Global site tag (gtag.js) - Google Analytics */
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + JSINFO.ga.gtagId;
document.body.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', JSINFO.ga.gtagId);
} else {
/* default google tracking initialization */
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
//noinspection CommaExpressionJS
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
//noinspection CommaExpressionJS
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
// initalize and set options
ga('create', JSINFO.ga.trackingId, 'auto', JSINFO.ga.options);
ga('set', 'forceSSL', true);
ga('set', 'anonymizeIp', JSINFO.ga.anonymizeIp);
// track pageview and action
ga('set', 'dimension1', JSINFO.ga.action);
ga('set', 'dimension2', JSINFO.ga.id);
ga('send', 'pageview', JSINFO.ga.pageview);
ga('send', 'event', 'wiki-action', JSINFO.ga.action, JSINFO.id, {
nonInteraction: true // this is an automatic event with the page load
});
// The hit payload is also send to the console
// https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks#overriding_a_task
if (JSINFO.ga.debug) {
ga(function(tracker) {
// Grab a reference to the default sendHitTask function.
var originalSendHitTask = tracker.get('sendHitTask');
// Overwrite and add an output to the console
tracker.set('sendHitTask', function(model) {
originalSendHitTask(model);
console.log("Doku Google Analytics Plugin Debug: Hit Payload: " + model.get('hitPayload'));
});
});
}
// track outgoing links, once the document was loaded
if (JSINFO.ga.trackOutboundLinks) {
jQuery(function() {
// https://support.google.com/analytics/answer/1136920?hl=en
jQuery('a.urlextern, a.interwiki').click(function() {
var url = this.href;
if (ga && ga.loaded) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon'
});
}
});
});
}
}
}