|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>AJS tester</title> |
| 4 | + </head> |
| 5 | + <body> |
| 6 | + <form method="GET"> |
| 7 | + <input type="text" name="writeKey" placeholder="Write key" /> |
| 8 | + <input type="text" name="cdnHost" placeholder="cdn.segment.com" /> |
| 9 | + <button>Load</button> |
| 10 | + </form> |
| 11 | + <p id='status-msg'></p> |
| 12 | + |
| 13 | + <button id='track-product-viewed' onclick="analytics.track('Product Viewed')"> |
| 14 | + Track: Product Viewed |
| 15 | + </button> |
| 16 | + <button id='track-checkout-started' onclick="analytics.track('Checkout Started')"> |
| 17 | + Track: Checkout Started |
| 18 | + </button> |
| 19 | + <button id='track-coupon-denied' onclick="analytics.track('Coupon Denied')"> |
| 20 | + Track: Coupon Denied |
| 21 | + </button> |
| 22 | + <br /> |
| 23 | + <button id='page-home' onclick="analytics.page('Home')">Page: Home</button> |
| 24 | + <button id='page-about' onclick="analytics.page('About')">Page: About</button> |
| 25 | + <button id='page-contact' onclick="analytics.page('Contact')">Page: Contact</button> |
| 26 | + <br /> |
| 27 | + <button id='identify-fathy' onclick="analytics.identify('fathy')">Identify: fathy</button> |
| 28 | + <button id='identify-spongebob' onclick="analytics.identify('spongebob')"> |
| 29 | + Identify: spongebob |
| 30 | + </button> |
| 31 | + <button |
| 32 | + id='group' |
| 33 | + onclick="analytics.group( |
| 34 | + 'group name', |
| 35 | + { |
| 36 | + 'address': { |
| 37 | + 'city': 'Vancouver', |
| 38 | + 'country': 'Canada', |
| 39 | + 'postalCode': 'V6b3E2', |
| 40 | + 'state': 'BC', |
| 41 | + 'street': '21 Jump St' |
| 42 | + }, |
| 43 | + 'avatar': 'does not exist', |
| 44 | + 'createdAt': new Date(), |
| 45 | + 'description': 'a fake group', |
| 46 | + 'email': 'email-me-not@domain.com', |
| 47 | + 'employees': 3, |
| 48 | + 'id': 1, |
| 49 | + 'industry': 'sw eng', |
| 50 | + 'name': 'libweb', |
| 51 | + 'phone': '555-pizza', |
| 52 | + 'website': 'www.google.com', |
| 53 | + 'plan': 'business' |
| 54 | + }, |
| 55 | + { |
| 56 | + 'integrations': { |
| 57 | + 'All': true |
| 58 | + } |
| 59 | + }, function() { console.log('group callback triggered')})" |
| 60 | + > |
| 61 | + Group |
| 62 | + </button> |
| 63 | + |
| 64 | + <button |
| 65 | + id='alias' |
| 66 | + onclick="analytics.alias('userId', 'previous id', { |
| 67 | + 'integrations': { 'All': true } |
| 68 | + }, function(){ console.log('alias callback triggered')})" |
| 69 | + > |
| 70 | + Alias |
| 71 | + </button> |
| 72 | + |
| 73 | + <br /> |
| 74 | + |
| 75 | + <script> |
| 76 | + const { searchParams } = new URL(document.location); |
| 77 | + const writeKey = searchParams.get("writeKey"); |
| 78 | + const cdnHost = searchParams.get("cdnHost") || 'cdn.segment.com'; |
| 79 | + const status = (s) => (document.querySelector("p").innerText = s); |
| 80 | + |
| 81 | + document.querySelector("input").value = writeKey; |
| 82 | + |
| 83 | + if (writeKey) { |
| 84 | + !(function () { |
| 85 | + var analytics = (window.analytics = window.analytics || []); |
| 86 | + if (!analytics.initialize) |
| 87 | + if (analytics.invoked) |
| 88 | + window.console && |
| 89 | + console.error && |
| 90 | + console.error("Segment snippet included twice."); |
| 91 | + else { |
| 92 | + analytics.invoked = !0; |
| 93 | + analytics.methods = [ |
| 94 | + "trackSubmit", |
| 95 | + "trackClick", |
| 96 | + "trackLink", |
| 97 | + "trackForm", |
| 98 | + "pageview", |
| 99 | + "identify", |
| 100 | + "reset", |
| 101 | + "group", |
| 102 | + "track", |
| 103 | + "ready", |
| 104 | + "alias", |
| 105 | + "debug", |
| 106 | + "page", |
| 107 | + "once", |
| 108 | + "off", |
| 109 | + "on", |
| 110 | + ]; |
| 111 | + analytics.factory = function (t) { |
| 112 | + return function () { |
| 113 | + var e = Array.prototype.slice.call(arguments); |
| 114 | + e.unshift(t); |
| 115 | + analytics.push(e); |
| 116 | + return analytics; |
| 117 | + }; |
| 118 | + }; |
| 119 | + for (var t = 0; t < analytics.methods.length; t++) { |
| 120 | + var e = analytics.methods[t]; |
| 121 | + analytics[e] = analytics.factory(e); |
| 122 | + } |
| 123 | + analytics.load = function (t, e) { |
| 124 | + var n = document.createElement("script"); |
| 125 | + n.type = "text/javascript"; |
| 126 | + n.async = !0; |
| 127 | + n.src = |
| 128 | + "http://" + |
| 129 | + cdnHost + |
| 130 | + "/analytics.js/v1/" + |
| 131 | + t + |
| 132 | + "/analytics.js"; |
| 133 | + var a = document.getElementsByTagName("script")[0]; |
| 134 | + a.parentNode.insertBefore(n, a); |
| 135 | + analytics._loadOptions = e; |
| 136 | + }; |
| 137 | + analytics.SNIPPET_VERSION = "4.1.0"; |
| 138 | + analytics.load(writeKey); |
| 139 | + analytics.page(); |
| 140 | + } |
| 141 | + })(); |
| 142 | + |
| 143 | + status("loading ajs"); |
| 144 | + |
| 145 | + analytics.ready(() => { |
| 146 | + analytics.reset(); |
| 147 | + var f = function ({ payload, next, integrations }) { |
| 148 | + next(payload); |
| 149 | + }; |
| 150 | + var f2 = function ({ payload, next, integrations }) { |
| 151 | + next(payload); |
| 152 | + }; |
| 153 | + analytics.addSourceMiddleware(f); |
| 154 | + analytics.addSourceMiddleware(f2); |
| 155 | + return status( |
| 156 | + `ajs ${analytics.VERSION} loaded, write key: ${analytics._integrations["Segment.io"].options.apiKey}` |
| 157 | + ); |
| 158 | + }); |
| 159 | + } else { |
| 160 | + status("ajs not loaded, enter a write key"); |
| 161 | + } |
| 162 | + </script> |
| 163 | + </body> |
| 164 | +</html> |
0 commit comments