|
14 | 14 | --> |
15 | 15 | <html> |
16 | 16 | <head> |
17 | | - <title>Asynchronous website/webapp examples for snowplow.js</title> |
| 17 | + <title>Asynchronous website/webapp examples for snowplow.js</title>localStorage.clear() |
18 | 18 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
19 | 19 |
|
20 | 20 | <!-- Snowplow starts plowing --> |
21 | | - <script type="text/javascript"> |
22 | | - window._snaq = window._snaq || []; |
23 | | - |
24 | | - window._snaq.push(['setLinkTrackingTimer', 5000]); |
25 | | - window._snaq.push(['setCollectorCf', 'd3rkrsqld9gmqf' ]); // Update to your CloudFront distribution subdomain |
26 | | - window._snaq.push(['setAppId', 'CFe23a']); // Site ID can be anything you want. Set it if you're tracking more than one site in this account |
27 | | - window._snaq.push(['setUserId', 'alex 123']); // Business-defined user ID |
28 | | - //window._snaq.push(['setUserIdFromLocation', 'id']); // To test this, reload the page with ?id=xxx |
29 | | - //window._snaq.push(['setUserIdFromCookie', '_sp_id.4209']) // Test this using Firefox because Chrome doesn't allow local cookies. |
30 | | - window._snaq.push(['setCustomUrl', '/overridden-url/']); // Override the page URL |
31 | | - window._snaq.push(['enableActivityTracking', 10, 10]); // Ping every 10 seconds after 10 seconds |
32 | | - window._snaq.push(['enableLinkClickTracking', 'barred', true]); |
33 | | - window._snaq.push(['setPlatform', 'mob']); |
34 | | - window._snaq.push(['encodeBase64', false]); // Default is true |
35 | | - //window._snaq.push(['enableUserFingerprint', false]); // Turn off user fingerprinting |
36 | | - //window._snaq.push(['setUserFingerprintSeed', 987654321]); // Set user fingerprint hash seed |
37 | | - window._snaq.push(['respectDoNotTrack', true]); // Prevent all tracking if browser's Do Not Track feature is enabled |
38 | | - // window._snaq.push(['trackPageView', 'Async Test']); // Track the page view with custom title |
39 | | - window._snaq.push(['trackPageView', , { // Auto-set page title; add page context |
| 21 | + <script type="text/javascript"> |
| 22 | + |
| 23 | + ;(function(p,l,o,w,i,n,g) { |
| 24 | + p['GlobalSnowplowNamespace'] = p['GlobalSnowplowNamespace']||[]; |
| 25 | + p['GlobalSnowplowNamespace'].push(i); |
| 26 | + p[i] = p[i] || function() { |
| 27 | + (p[i].q = p[i].q||[]).push(arguments); |
| 28 | + }; |
| 29 | + p[i].q = p[i].q || []; |
| 30 | + n = l.createElement(o); |
| 31 | + g = l.getElementsByTagName(o)[0]; |
| 32 | + n.async = 1; |
| 33 | + n.src = w; |
| 34 | + g.parentNode.insertBefore(n,g); |
| 35 | + }(window, document, 'script', '../../dist/snowplow.js', 'new_name_here')); |
| 36 | + |
| 37 | + window.new_name_here('newTracker', 'primaryTrackerNamespace', 'd3rkrsqld9gmqf.cloudfront.net'); |
| 38 | + |
| 39 | + window.new_name_here('setAppId', 'CFe23a'); // Site ID can be anything you want. Set it if you're tracking more than one site in this account |
| 40 | + window.new_name_here('setUserId', 'alex 123'); // Business-defined user ID |
| 41 | + //window.new_name_here('setUserIdFromLocation', 'id'); // To test this, reload the page with ?id=xxx |
| 42 | + //window.new_name_here('setUserIdFromCookie', '_sp_id.4209') // Test this using Firefox because Chrome doesn't allow local cookies. |
| 43 | + window.new_name_here('setCustomUrl', '/overridden-url/'); // Override the page URL |
| 44 | + window.new_name_here('enableActivityTracking', 10, 10); // Ping every 10 seconds after 10 seconds |
| 45 | + window.new_name_here('enableLinkClickTracking', 'barred', true); |
| 46 | + window.new_name_here('setPlatform', 'mob'); |
| 47 | + window.new_name_here('encodeBase64', false); // Default is true |
| 48 | + window.new_name_here('enableUserFingerprinting', true); // Turn on user fingerprinting |
| 49 | + window.new_name_here('respectDoNotTrack', true); // Prevent all tracking if browser's Do Not Track feature is enabled |
| 50 | + // window.new_name_here('trackPageView', 'Async Test'); // Track the page view with custom title |
| 51 | + window.new_name_here('trackPageView', null , { // Auto-set page title; add page context |
40 | 52 | page: { |
41 | 53 | page_type: 'test', |
42 | 54 | last_updated: new Date(2014,1,26) |
|
45 | 57 | user_type: 'tester', |
46 | 58 |
|
47 | 59 | } |
48 | | - } ]); |
49 | | - |
50 | | - (function() { |
51 | | - var sp = document.createElement('script'); sp.type = 'text/javascript'; sp.async = true; sp.defer = true; |
52 | | - //sp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://d1fc8wv8zag5ca.cloudfront.net/0.13.0/sp.js'; |
53 | | - sp.src = '../../dist/snowplow.js'; // For testing |
54 | | - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sp, s); |
55 | | - })(); |
| 60 | + } ); |
| 61 | + |
56 | 62 | </script> |
57 | 63 | <!-- Snowplow stops plowing --> |
58 | 64 |
|
59 | 65 | <!-- Example events --> |
60 | 66 | <script type="text/javascript"> |
61 | 67 |
|
62 | 68 | function playMix() { |
63 | | - alert("Playing a DJ mix"); |
64 | | - window._snaq.push(['trackStructEvent', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0']); |
| 69 | + alert("Playing a DJ mix"); console.log(window.new_name_here.q) |
| 70 | + window.new_name_here('trackStructEvent', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0'); |
65 | 71 | } |
66 | 72 | function addProduct() { |
67 | 73 | alert("Adding a product to basket"); |
68 | | - window._snaq.push(['trackStructEvent', 'Checkout', 'Add', 'ASO01043', 'blue:xxl', '2.0', { user: { fb_uid: '123456 x' } } ]); |
| 74 | + window.new_name_here('trackStructEvent', 'Checkout', 'Add', 'ASO01043', 'blue:xxl', '2.0', { user: { fb_uid: '123456 x' } } ); |
69 | 75 | } |
70 | 76 | function viewProduct() { |
71 | 77 | alert("Viewing a product"); |
72 | | - window._snaq.push(['trackUnstructEvent', 'Viewed Product', |
| 78 | + window.new_name_here('trackUnstructEvent', 'Viewed Product', |
73 | 79 | { |
74 | 80 | product_id: 'ASO01043', |
75 | 81 | category: 'Dresses', |
|
79 | 85 | sizes: ['xs', 's', 'l', 'xl', 'xxl'], |
80 | 86 | available_since$dt: new Date(2013,3,7) |
81 | 87 | } |
82 | | - ]); |
| 88 | + ); |
83 | 89 | } |
84 | 90 |
|
85 | 91 | function addEcommerceTransaction() { |
|
88 | 94 | var orderId = 'order-123'; |
89 | 95 |
|
90 | 96 | // addTrans sets up the transaction, should be called first. |
91 | | - window._snaq.push(['addTrans', |
| 97 | + window.new_name_here('addTrans', |
92 | 98 | orderId, // order ID - required |
93 | 99 | '', // affiliation or store name |
94 | 100 | '8000', // total - required |
|
98 | 104 | '', // state or province |
99 | 105 | '', // country |
100 | 106 | 'JPY' // currency |
101 | | - ]); |
| 107 | + ); |
102 | 108 |
|
103 | 109 | // addItem might be called for each item in the shopping cart, |
104 | 110 | // or not at all. |
105 | | - window._snaq.push(['addItem', |
| 111 | + window.new_name_here('addItem', |
106 | 112 | orderId, // order ID - required |
107 | 113 | '1001', // SKU - required |
108 | 114 | 'Blue t-shirt', // product name |
|
111 | 117 | '2', // quantity - required |
112 | 118 | 'JPY', // currency |
113 | 119 | { products: { "launch_date$tm": new Date(2013,3,7) } } // context |
114 | | - ]); |
| 120 | + ); |
115 | 121 |
|
116 | | - window._snaq.push(['addItem', |
| 122 | + window.new_name_here('addItem', |
117 | 123 | orderId, // order ID - required |
118 | 124 | '1002', // SKU - required |
119 | 125 | 'Red shoes', // product name |
120 | 126 | '', // category |
121 | 127 | '4000', // unit price - required |
122 | 128 | '1', // quantity - required |
123 | 129 | 'JPY' // currency |
124 | | - ]); |
| 130 | + ); |
125 | 131 |
|
126 | 132 | // trackTrans sends the transaction to Snowplow tracking servers. |
127 | 133 | // Must be called last to commit the transaction. |
128 | | - window._snaq.push(['trackTrans']); |
| 134 | + window.new_name_here('trackTrans'); |
129 | 135 |
|
130 | 136 | } |
131 | 137 | </script> |
|
0 commit comments