-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
198 lines (177 loc) · 9.53 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Google Analytics Ecommerce Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-NTXJBNL');
(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.js','ga');
ga('create', 'UA-87135556-1', 'auto');
ga('require', 'ecommerce');
ga('send', 'pageview');
ga('set', 'userId', 'USER-001'); // Set the user ID using signed-in user_id.
ga('ecommerce:addTransaction', {
'id': 'T-1000', // Transaction ID. Required.
'affiliation': 'Merkur24', // Affiliation or store name.
'revenue': '1.5', // Grand Total.
'shipping': '0.5', // Shipping.
'tax': '0.4' // Tax.
});
ga('ecommerce:addItem', {
'id': 'ITEM-1234', // Transaction ID. Required.
'name': 'Shop Fee', // Product name. Required.
'sku': 'ENTRY001', // SKU/code.
'category': 'Fee', // Category or variation.
'price': '1.5', // Unit price.
'quantity': '1' // Quantity.
});
ga('ecommerce:send');
setUser = function () {
var userId = document.getElementById('inputUserId').value;
ga('set', 'userId', userId);
alert('Loggedin user ' + userId);
}
createTransaction = function () {
var transactionId = document.getElementById('inputTransactionId').value;
ga('ecommerce:addTransaction', {
'id': transactionId, // Transaction ID. Required.
'affiliation': 'Merkur24', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
});
alert('transactionId set to ' + transactionId);
}
addToCart = function () {
var itemId = document.getElementById('inputItemId').value;
var itemName = document.getElementById('inputItemName').value;
var price = document.getElementById('inputPrice').value;
ga('ecommerce:addItem', {
'id': itemId, // Transaction ID. Required.
'name': itemName, // Product name. Required.
'sku': 'SKU' + itemId, // SKU/code.
'category': 'Kittens', // Category or variation.
'price': price, // Unit price.
'quantity': '1' // Quantity.
});
var ul = document.getElementById('items');
var li = document.createElement("li");
li.appendChild(document.createTextNode(itemName + ', price ' + price));
ul.appendChild(li);
}
buy = function () {
ga('ecommerce:send');
alert('Bought');
}
clearCart = function () {
ga('ecommerce:clear');
document.getElementById('items').innerText = '';
alert('Cancelled');
}
</script>
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NTXJBNL"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<section class="page-header">
<h1 class="project-name">Google Analytics Ecommerce Example</h1>
<h2 class="project-tagline"></h2>
<a href="https://github.com/skocic/ga" class="btn">View on GitHub</a>
<a href="https://github.com/skocic/ga/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/skocic/ga/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<a id="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>
<h3>Page Intro</h3>
<p>This is an example for Ecommerce tracking in Google Analytics. For this to work, you need to include your
own ID in the form of <code>UA-XXXXXXX-X</code> in the header</p>
<p>Page view is automatically triggered in header with <code>ga('send', 'pageview');</code></p>
<p>Shop fee transaction is automatically triggered
<pre>ga('ecommerce:addTransaction', {
'id': 'T-1000', // Transaction ID. Required.
'affiliation': 'Merkur24', // Affiliation or store name.
'revenue': '1.5', // Grand Total.
'shipping': '0.5', // Shipping.
'tax': '0.4' // Tax.
});
ga('ecommerce:addItem', {
'id': 'ITEM-1234', // Transaction ID. Required.
'name': 'Shop Fee', // Product name. Required.
'sku': 'ENTRY001', // SKU/code.
'category': 'Fee', // Category or variation.
'price': '1.5', // Unit price.
'quantity': '1' // Quantity.
});
ga('ecommerce:send');</pre>
</p>
<p>Read more on <a href="https://support.google.com/analytics/answer/1009612?hl=en">Set up Ecommerce Tracking</a>
</p>
<h3>Trigger manual transactions</h3>
<h4>User login</h4>
<div class="form-group form-inline">
<label for="inputUserId">User ID</label>
<input type="text" class="form-control" id="inputUserId" placeholder="USER-001">
<button onclick="setUser();" class="btn btn-default">Sign-in this user</button>
</div>
<h4>Create transaction</h4>
<div class="form-group form-inline">
<label for="inputTransactionId">Transaction ID</label>
<input type="text" class="form-control" id="inputTransactionId" placeholder="TRAN-003" value="TRAN-003">
<button onclick="createTransaction();" class="btn btn-default">Create transaction</button>
</div>
<h4>Add Items to cart</h4>
<div class="form-group">
<label for="inputItemId">Item ID</label>
<input type="text" class="form-control" id="inputItemId" placeholder="ITEM-123" value="ITEM-123">
<label for="inputItemName">Name</label>
<input type="text" class="form-control" id="inputItemName" placeholder="Kitten food" value="Kitten food">
<label for="inputPrice">Price</label>
<div class="input-group">
<div class="input-group-addon">EUR</div>
<input type="text" class="form-control" id="inputPrice" placeholder="3.99" value="3.99">
</div>
<label></label>
<div class="input-group">
<button class="btn btn-default" onclick="addToCart();">Add this item</button>
</div>
</div>
<div id="items"></div>
<div class="form-group">
<button onclick="clearCart();" class="btn btn-warning">Cancel</button>
<button onclick="buy();" class="btn btn-primary">Buy</button>
</div>
<blockquote>Keep in mind that it can take 24 hours to see the results as they are refreshed once a day.</blockquote>
<p>In my experience, doing it before midnight, makes them available in the morning. Good to know for
experimenting...</p>
<img src="images/e-commerce.png">
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/skocic/ga">Google Analytics Ecommerce Example</a> is
maintained by <a href="https://github.com/skocic">skocic</a>.</span>
<span class="site-footer-credits">Using the <a href="https://github.com/jasonlong/cayman-theme">Cayman
theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
</footer>
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>