-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathga-task-manager.html
51 lines (39 loc) · 1.71 KB
/
ga-task-manager.html
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
<!doctype html>
<html>
<head>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();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_debug.js','ga');
window.ga_debug = {trace: true};
ga('create', 'GA-PROPERTY-ID', 'auto');
// Require the plugin
ga('require', 'gaTaskManager');
// Add a function to customTask
ga('GaTaskManager:addFunctionToTask', 'customTask', 'logShinyString', function(model){
console.log("Look at my shiny new random customTask");
});
// Add a second function to customTask
ga('GaTaskManager:addFunctionToTask', 'customTask', 'logShinyStringAgain', function(model){
console.log("Look at my shiny second random customTask which will be executed after the first!");
});
// Set Dimensions with a static string value
ga('GaTaskManager:setCustomDimension', 1, 14)
// Set Dimensions with function to return the value at time of execution
ga('GaTaskManager:setCustomDimension', 2, function(){return Date.now() / 1000 | 0})
ga('send', 'pageview');
// Remove logShinyStringAgain function
ga('GaTaskManager:removeFunctionFromTask', 'customTask', 'logShinyStringAgain');
// Unset the function setting the dimension at every hit which we added earlier
ga('GaTaskManager:unsetCustomDimension', 1);
// Trigger a second hit after 5 seconds
setTimeout(function () {
ga('send', 'pageview');
}, 5000);
</script>
<script async src="/ga-task-manager.js"></script>
</head>
<body>
</body>
</html>