|
1 |
| -// this code is related to implementing the A/B testing tool VMO: https://vwo.com/ |
2 |
| -// Whenever this script is updated, ensure that any changes are reflected in the |
3 |
| -// error handling in App.tsx, especially for any elements that change opacity of the page. |
4 | 1 | /* eslint-disable */
|
5 | 2 | // @ts-nocheck
|
| 3 | + |
| 4 | +import {getFlagValue} from 'src/shared/utils/featureFlag' |
| 5 | + |
| 6 | +/* This file is exclusively for third-party analytics tools used by the Cloud2 UI. */ |
| 7 | + |
| 8 | +/* This code implements the A/B testing tool VWO: https://vwo.com/ |
| 9 | + The copy is largely copy-pasted from VWO instructions and is not maintained by InfluxData. |
| 10 | + Whenever this script is updated, ensure that any changes are reflected in the |
| 11 | + error handling in App.tsx, especially for any elements that change opacity of the page. */ |
6 | 12 | export const executeVWO = () => {
|
7 | 13 | window._vwo_code =
|
8 | 14 | window._vwo_code ||
|
@@ -116,3 +122,86 @@ export const executeVWO = () => {
|
116 | 122 | return code
|
117 | 123 | })()
|
118 | 124 | }
|
| 125 | + |
| 126 | +const HEAP_API_SCRIPT_SRC = 'heap-api.com' |
| 127 | + |
| 128 | +/* |
| 129 | + The JS code in this function is copied from the installation instructions |
| 130 | + at https://developers.heap.io/docs/web and is not maintained by InfluxData. |
| 131 | +
|
| 132 | + Semicolons have been added to avoid ASI issues because this script uses IIFEs. |
| 133 | + // Example: https://circleci.com/blog/ci-cd-for-js-iifes/ |
| 134 | +*/ |
| 135 | +export const executeHeap = () => { |
| 136 | + // Retrieve the heap analytics id appropriate to the environment from ConfigCat. |
| 137 | + const heapId = getFlagValue('heapanalyticsid') |
| 138 | + if (!heapId) { |
| 139 | + return |
| 140 | + } |
| 141 | + |
| 142 | + // This block is imported from Heap. |
| 143 | + ;(window.heapReadyCb = window.heapReadyCb || []), |
| 144 | + (window.heap = window.heap || []), |
| 145 | + (heap.load = function (e, t) { |
| 146 | + ;(window.heap.envId = e), |
| 147 | + (window.heap.clientConfig = t = t || {}), |
| 148 | + (window.heap.clientConfig.shouldFetchServerConfig = !1) |
| 149 | + var a = document.createElement('script') |
| 150 | + ;(a.type = 'text/javascript'), |
| 151 | + (a.async = !0), |
| 152 | + (a.src = 'https://cdn.us.heap-api.com/config/' + e + '/heap_config.js') |
| 153 | + var r = document.getElementsByTagName('script')[0] |
| 154 | + r.parentNode.insertBefore(a, r) |
| 155 | + var n = [ |
| 156 | + 'init', |
| 157 | + 'startTracking', |
| 158 | + 'stopTracking', |
| 159 | + 'track', |
| 160 | + 'resetIdentity', |
| 161 | + 'identify', |
| 162 | + 'getSessionId', |
| 163 | + 'getUserId', |
| 164 | + 'getIdentity', |
| 165 | + 'addUserProperties', |
| 166 | + 'addEventProperties', |
| 167 | + 'removeEventProperty', |
| 168 | + 'clearEventProperties', |
| 169 | + 'addAccountProperties', |
| 170 | + 'addAdapter', |
| 171 | + 'addTransformer', |
| 172 | + 'addTransformerFn', |
| 173 | + 'onReady', |
| 174 | + 'addPageviewProperties', |
| 175 | + 'removePageviewProperty', |
| 176 | + 'clearPageviewProperties', |
| 177 | + 'trackPageview', |
| 178 | + ], |
| 179 | + i = function (e) { |
| 180 | + return function () { |
| 181 | + var t = Array.prototype.slice.call(arguments, 0) |
| 182 | + window.heapReadyCb.push({ |
| 183 | + name: e, |
| 184 | + fn: function () { |
| 185 | + heap[e] && heap[e].apply(heap, t) |
| 186 | + }, |
| 187 | + }) |
| 188 | + } |
| 189 | + } |
| 190 | + for (var p = 0; p < n.length; p++) heap[n[p]] = i(n[p]) |
| 191 | + }) |
| 192 | + |
| 193 | + heap.load(heapId.toString()) |
| 194 | +} |
| 195 | + |
| 196 | +// This unloads all artifacts from the Heap script if an error is encountered. |
| 197 | +export const unloadHeap = () => { |
| 198 | + delete window.heap |
| 199 | + delete window.heapReadyCb |
| 200 | + |
| 201 | + const scripts = document.getElementsByTagName('script') |
| 202 | + for (let s of scripts) { |
| 203 | + if (s.src.includes(HEAP_API_SCRIPT_SRC)) { |
| 204 | + s.remove() |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments