({ config, instance })
| 127 | } |
| 128 | |
| 129 | function initialize({ config, instance }) { |
| 130 | const { disableAnonymousTraffic, writeKey, customScriptSrc } = config |
| 131 | if (!writeKey) { |
| 132 | throw new Error('No segment writeKey') |
| 133 | } |
| 134 | /* Disable segment.com if user is not yet identified. Save on Monthly MTU bill $$$ */ |
| 135 | const userID = instance.user('userId') |
| 136 | if (!userID && disableAnonymousTraffic) { |
| 137 | return false |
| 138 | } |
| 139 | /* eslint-disable */ |
| 140 | !function() { |
| 141 | var analytics = window.analytics = window.analytics || [] |
| 142 | |
| 143 | function isScriptLoaded() { |
| 144 | const scripts = document.getElementsByTagName('script') |
| 145 | const scriptMatch = customScriptSrc || 'cdn.segment.com/analytics.js/v1/' |
| 146 | return !!Object.keys(scripts).filter((key) => { |
| 147 | const scriptInfo = scripts[key] || {} |
| 148 | const src = scriptInfo.src || '' |
| 149 | return src.indexOf(scriptMatch) > -1 |
| 150 | }).length |
| 151 | } |
| 152 | |
| 153 | if (!analytics.initialize) { |
| 154 | if (!isScriptLoaded()) { |
| 155 | analytics.invoked = !0; |
| 156 | analytics.methods = ["trackSubmit", "trackClick", "trackLink", "trackForm", "pageview", "identify", "reset", "group", "track", "ready", "alias", "debug", "page", "once", "off", "on"]; |
| 157 | analytics.factory = function(t) { |
| 158 | return function() { |
| 159 | var e = Array.prototype.slice.call(arguments); |
| 160 | e.unshift(t); |
| 161 | analytics.push(e); |
| 162 | return analytics |
| 163 | } |
| 164 | }; |
| 165 | for (var t = 0; t < analytics.methods.length; t++) { |
| 166 | var e = analytics.methods[t]; |
| 167 | analytics[e] = analytics.factory(e) |
| 168 | } |
| 169 | analytics.load = function(t, e) { |
| 170 | var n = document.createElement("script"); |
| 171 | n.type = "text/javascript"; |
| 172 | n.async = !0; |
| 173 | n.src = customScriptSrc || "https://cdn.segment.com/analytics.js/v1/" + t + "/analytics.min.js"; |
| 174 | n.id = 'segment-io' |
| 175 | var a = document.getElementsByTagName("script")[0]; |
| 176 | a.parentNode.insertBefore(n, a); |
| 177 | analytics._loadOptions = e |
| 178 | }; |
| 179 | analytics.SNIPPET_VERSION = "4.1.0"; |
| 180 | analytics.load(writeKey); |
| 181 | } |
| 182 | } |
| 183 | }(); |
| 184 | /* eslint-enable */ |
| 185 | } |
| 186 |
no test coverage detected