-
Notifications
You must be signed in to change notification settings - Fork 0
/
ga.html
77 lines (60 loc) · 3.18 KB
/
ga.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript">
var gaPlugin;
function initialize() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
// Note: A request for permission is REQUIRED by google. You probably want to do this just once, though, and remember the answer for subsequent runs.
navigator.notification.confirm('GA_PLUGIN would like your permission to collect usage data. No personal or user identifiable data will be collected.', permissionCallback, 'Attention', 'Allow,Deny');
}
function permissionCallback (button) {
if (button === 1)
gaPlugin.init(nativePluginResultHandler, nativePluginErrorHandler, "UA-20914687-2", 10);
}
function nativePluginResultHandler (result) {
//alert('nativePluginResultHandler - '+result);
console.log('nativePluginResultHandler: '+result);
}
function nativePluginErrorHandler (error) {
//alert('nativePluginErrorHandler - '+error);
console.log('nativePluginErrorHandler: '+error);
}
function TrackButtonClicked() {
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "Button", "Click", "event only", 1);
}
function VariableButtonClicked() {
// Set a dimension based on index and value. Make sure you have added a dimension in the GA dashboard to the
// default property for the passed in index, and your desired scope. GA allows up to 20 dimensions for a free account
gaPlugin.setVariable( nativePluginResultHandler, nativePluginErrorHandler, 1, "Purple");
// dimensions are are passed to the next event sent to GA. go ahead and fire off an event with the label (key) of your choice
// In this example, the label for custom dimension 1 will show up in the dashboard as "favoriteColor". This is much more efficent
// than the old custom variable method introduced in V1, (plus you get 20 free dimensions vs 5 free custom variables)
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "event with variable", "set variable", "favoriteColor", 1);
}
function PageButtonClicked() {
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "some.url.com");
}
function goingAway() {
gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);
}
</script>
</head>
<body onload="initialize();" onunload="goingAway();" id="stage" class="theme">
<h1>Test Google Analytics Plugin</h1>
<div class="space"></div>
<div>
<a href="#" class="btn large" onclick="TrackButtonClicked();">Track Event</a>
<a href="#" class="btn large" onclick="VariableButtonClicked();">Track Event with Variable</a>
<a href="#" class="btn large" onclick="PageButtonClicked();">Track Page</a>
</div>
</body>
</html>