|
| 1 | +<!DOCTYPE html> |
| 2 | + |
| 3 | +<!-- |
| 4 | + ! Copyright (c) 2012-2013 Snowplow Analytics Ltd. All rights reserved. |
| 5 | + ! |
| 6 | + ! This program is licensed to you under the Apache License Version 2.0, |
| 7 | + ! and you may not use this file except in compliance with the Apache License Version 2.0. |
| 8 | + ! You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. |
| 9 | + ! |
| 10 | + ! Unless required by applicable law or agreed to in writing, |
| 11 | + ! software distributed under the Apache License Version 2.0 is distributed on an |
| 12 | + ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + ! See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. |
| 14 | +--> |
| 15 | +<html> |
| 16 | + <head> |
| 17 | + <title>Cookieless tracking example for snowplow.js</title> |
| 18 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 19 | + |
| 20 | + <!-- Snowplow starts plowing --> |
| 21 | + <script type="text/javascript"> |
| 22 | + ;(function(p, l, o, w, i, n, g) { |
| 23 | + if (!p[i]) { |
| 24 | + p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || [] |
| 25 | + p.GlobalSnowplowNamespace.push(i) |
| 26 | + 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 | + } |
| 36 | + })(window, document, 'script', '../sp.js', 'snowplow') |
| 37 | + |
| 38 | + window.snowplow('newTracker', 'cf', '127.0.0.1:9090', { |
| 39 | + // Initialise a tracker |
| 40 | + anonymousTracking: true, |
| 41 | + encodeBase64: false, // Default is true |
| 42 | + appId: 'CFe23a', // Site ID can be anything you want. Set it if you're tracking more than one site in this account |
| 43 | + platform: 'mob', |
| 44 | + contexts: { |
| 45 | + webPage: true, |
| 46 | + gaCookies: true, |
| 47 | + performanceTiming: true |
| 48 | + } |
| 49 | + }) |
| 50 | + </script> |
| 51 | + <!-- Snowplow stops plowing --> |
| 52 | + </head> |
| 53 | + |
| 54 | + <body> |
| 55 | + <header> |
| 56 | + <h1>Cookieless_tracking_examples_for_snowplow.js</h1> |
| 57 | + |
| 58 | + <p> |
| 59 | + Warning: if your browser's Do Not Track feature is enabled and |
| 60 | + respectDoNotTrack is enabled, all tracking will be prevented. |
| 61 | + </p> |
| 62 | + <p> |
| 63 | + If you are viewing the page using a file URL, you must edit the script |
| 64 | + URL in the Snowplow tag to include an http scheme. Otherwise a file |
| 65 | + scheme will be inferred and the page will attempt to load sp.js from the |
| 66 | + local filesystem.. |
| 67 | + </p> |
| 68 | + </header> |
| 69 | + |
| 70 | + <nav> |
| 71 | + <div id="login-form" style="display:block"> |
| 72 | + <span class="fontawesome-user"></span> |
| 73 | + <input type="text" id="user" placeholder="Username" /> |
| 74 | + |
| 75 | + <span class="fontawesome-lock"></span> |
| 76 | + <input type="password" id="pass" placeholder="Password" /> |
| 77 | + |
| 78 | + <input type="submit" value="Login" onclick="login()" /> |
| 79 | + </div> |
| 80 | + </nav> |
| 81 | + |
| 82 | + <section> |
| 83 | + <div id="logout-form" style="display:none"> |
| 84 | + <button type="button" onclick="logout()">Logout</button> |
| 85 | + </div> |
| 86 | + </section> |
| 87 | + <section> |
| 88 | + <button type="button" onclick="playMix()">Play a Mix</button> |
| 89 | + </section> |
| 90 | + |
| 91 | + <script> |
| 92 | + function playMix() { |
| 93 | + alert('Playing a DJ mix') |
| 94 | + window.snowplow( |
| 95 | + 'trackStructEvent', |
| 96 | + 'Mixes', |
| 97 | + 'Play', |
| 98 | + 'MRC/fabric-0503-mix', |
| 99 | + '', |
| 100 | + '0.0' |
| 101 | + ) |
| 102 | + } |
| 103 | + |
| 104 | + function login() { |
| 105 | + window.snowplow('enableUserTracking', 'localStorage') |
| 106 | + window.snowplow('setUserId', 'alex 123') // Business-defined user ID |
| 107 | + window.snowplow('setUserIdFromLocation', 'id') // To test this, reload the page with ?id=xxx |
| 108 | + window.snowplow('setUserIdFromCookie', '_sp_id.4209') // Test this using Firefox because Chrome doesn't allow local cookies. |
| 109 | + window.snowplow('setCustomUrl', '/overridden-url/') // Override the page URL |
| 110 | + window.snowplow('enableActivityTracking', 10, 10) // Ping every 10 seconds after 10 seconds |
| 111 | + |
| 112 | + toggle() |
| 113 | + return false |
| 114 | + } |
| 115 | + |
| 116 | + function logout() { |
| 117 | + window.snowplow('disableUserTracking', 'localStorage') |
| 118 | + toggle() |
| 119 | + |
| 120 | + return false |
| 121 | + } |
| 122 | + |
| 123 | + function toggle() { |
| 124 | + var login = document.getElementById('login-form') |
| 125 | + var logout = document.getElementById('logout-form') |
| 126 | + |
| 127 | + if (login.style.display == 'block') { |
| 128 | + login.style.display = 'none' |
| 129 | + logout.style.display = 'block' |
| 130 | + } else { |
| 131 | + login.style.display = 'block' |
| 132 | + logout.style.display = 'none' |
| 133 | + } |
| 134 | + } |
| 135 | + </script> |
| 136 | + </body> |
| 137 | +</html> |
0 commit comments