@ohos-ports/vite-plugin-radar 0.11.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Sacha Stafyniak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,337 @@
1
+ # vite-plugin-radar
2
+
3
+ Analytics loader for vite that support Google Analytics, Google Tag Manager, Facebook Pixel,
4
+ Linkedin Insight, Yandex Metrica, Baidu Tongji, Microsoft Advertising and Unbounce
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm i --save-dev vite-plugin-radar # yarn add -D vite-plugin-radar
10
+ ```
11
+
12
+ ## Add it to vite.config.js
13
+
14
+ ```ts
15
+ // vite.config.js
16
+ import { VitePluginRadar } from 'vite-plugin-radar'
17
+
18
+ export default {
19
+ plugins: [
20
+ VitePluginRadar({
21
+ // Google Analytics tag injection
22
+ analytics: {
23
+ id: 'G-XXXXX',
24
+ },
25
+ })
26
+ ],
27
+ }
28
+ ```
29
+
30
+ ## Options
31
+
32
+ Every provider ships with sensible hard-coded defaults (script/endpoint urls, script
33
+ attributes, snippet versions, loader snippets, …). All of them live in each provider's
34
+ `default-values.ts` and can be overridden through the provider options — handy for
35
+ self-hosting or proxying third-party scripts. The commented lines below show the
36
+ overridable defaults for each provider.
37
+
38
+ ```ts
39
+ // vite.config.js
40
+ import { VitePluginRadar } from 'vite-plugin-radar'
41
+
42
+ export default {
43
+ plugins: [
44
+ VitePluginRadar({
45
+ /**
46
+ * enable or disable scripts injection in development
47
+ * default: false
48
+ */
49
+ enableDev: true,
50
+
51
+ // Google Analytics (multiple tag can be set with an array)
52
+ analytics: [
53
+ {
54
+ /**
55
+ * Measurement id
56
+ */
57
+ id: 'G-XXXXX',
58
+
59
+ /**
60
+ * Override the gtag.js origin / path, the `async` flag,
61
+ * or the dataLayer bootstrap snippet (all optional)
62
+ */
63
+ source: 'https://www.googletagmanager.com',
64
+ // basePath: '/gtag/js',
65
+ // async: true,
66
+ // loader: 'window.dataLayer = window.dataLayer || [];...',
67
+
68
+ /**
69
+ * disable tracking for this measurement
70
+ * window['ga-disable-MEASUREMENT_ID'] = true
71
+ * @see https://developers.google.com/analytics/devguides/collection/ga4/disable-analytics
72
+ */
73
+ disable: true,
74
+
75
+ /**
76
+ * You can configure all settings provided by analytics here
77
+ * @see https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id
78
+ * @see https://developers.google.com/analytics/devguides/collection/ga4/disable-page-view
79
+ * @see https://developers.google.com/analytics/devguides/collection/ga4/display-features
80
+ */
81
+ config: {
82
+ cookie_domain: 'auto',
83
+ cookie_expires: 63072000,
84
+ cookie_prefix: 'none',
85
+ cookie_update: true,
86
+ cookie_flags: '',
87
+ send_page_view: true,
88
+ allow_google_signals: true,
89
+ allow_ad_personalization_signals: true,
90
+ },
91
+
92
+ /**
93
+ * Set default values for "consent mode"
94
+ * @see https://developers.google.com/tag-platform/devguides/consent
95
+ * @see https://support.google.com/analytics/answer/9976101
96
+ */
97
+ consentDefaults: {
98
+ analytics_storage: 'granted',
99
+ ad_storage: 'denied',
100
+ wait_for_update: 500
101
+ },
102
+
103
+ /**
104
+ * You set persitent values
105
+ * @see https://developers.google.com/analytics/devguides/collection/ga4/persistent-values
106
+ */
107
+ persistentValues: {
108
+ currency: 'USD',
109
+ }
110
+ },
111
+ // You can add as many measurement id as you need
112
+ {
113
+ id: 'UA-YYYYY',
114
+ },
115
+ ],
116
+
117
+ // Google Tag Manager (multiple tag can be set with an array)
118
+ gtm: [
119
+ {
120
+ id: 'GTM-XXXXX',
121
+
122
+ // You can set custom source for gtm script and noscript
123
+ gtmBase: 'https://www.custom.com/gtm.js',
124
+ nsBase: 'https://www.custom.com/ns.html',
125
+ // You can also override the `async` flag and the dataLayer bootstrap snippet
126
+ // async: true,
127
+ // loader: 'window.dataLayer = window.dataLayer || [];...',
128
+ // You can optionally define the environment for the gtm.
129
+ environment: {
130
+ auth: 'X1YzAB2CDEFGh3ijklmnoP',
131
+ preview: 'env-x',
132
+ },
133
+ }
134
+ ],
135
+
136
+ // Facebook Pixel (multiple tag can be set with an array)
137
+ pixel: [
138
+ {
139
+ id: 'XXXXXXX',
140
+ // Optional overrides for the script/noscript urls and tracked event
141
+ // script: 'https://connect.facebook.net/en_US/fbevents.js',
142
+ // noScript: 'https://www.facebook.com/tr',
143
+ // event: 'PageView',
144
+ }
145
+ ],
146
+
147
+ // VK Retargeting (multiple tag can be set with an array)
148
+ retargeting: [
149
+ {
150
+ id: 'VK-RTRG-XXXXXX-XXXXX',
151
+ // Optional overrides for the script/noscript urls and hit call
152
+ // script: 'https://vk.com/js/api/openapi.js?169',
153
+ // noScript: 'https://vk.com/rtrg',
154
+ // hit: 'VK.Retargeting.Hit()',
155
+ }
156
+ ],
157
+
158
+ // Linkedin Insight (multiple tag can be set with an array)
159
+ linkedin: [
160
+ {
161
+ id: 'XXXXXXX',
162
+ // Optional overrides for the script/noscript urls and async flag
163
+ // script: 'https://snap.licdn.com/li.lms-analytics/insight.min.js',
164
+ // noScript: 'https://px.ads.linkedin.com/collect/',
165
+ // async: true,
166
+ }
167
+ ],
168
+
169
+ // Baidu Tongji (multiple tag can be set with an array)
170
+ tongji: [
171
+ {
172
+ id: 'XXXXXXX',
173
+ // Optional overrides for the script url, async flag and auto pageview
174
+ // script: 'https://hm.baidu.com/hm.js',
175
+ // async: true,
176
+ // autoPageview: true,
177
+ }
178
+ ],
179
+
180
+ // Yandex Metrica (multiple tag can be set with an array)
181
+ metrica: [
182
+ {
183
+ id: 'XXXXXXX',
184
+
185
+ // Optional overrides for the script/noscript urls
186
+ // script: 'https://mc.yandex.ru/metrika/tag.js',
187
+ // noScript: 'https://mc.yandex.ru/watch/',
188
+
189
+ /**
190
+ * You can configure all settings provided by metrika here
191
+ * @see https://yandex.com/support/metrica/code/counter-initialize.html
192
+ */
193
+ config: {
194
+ defer: true,
195
+ clickmap: true,
196
+ trackLinks: true,
197
+ accurateTrackBounce: true,
198
+ childIframe: true,
199
+ webvisor: true,
200
+ trackHash: true,
201
+ triggerEvent: true,
202
+ ecommerce: 'dataLayer',
203
+ trustedDomains: ['example.com'],
204
+ type: 0,
205
+ params: {},
206
+ userParams: {}
207
+ }
208
+ }
209
+ ],
210
+
211
+ // Microsoft Analytics (only one tag can be set)
212
+ microsoft: {
213
+ id: 'XXXXX',
214
+ // Optional overrides for the UET script url and async flag
215
+ // script: '//bat.bing.com/bat.js',
216
+ // async: 1,
217
+ },
218
+
219
+ // Microsoft Clarity (only one tag can be set)
220
+ microsoftClarity: {
221
+ id: 'XXXXX',
222
+ // Optional overrides for the script url and async flag
223
+ // script: 'https://www.clarity.ms/tag/',
224
+ // async: 1,
225
+ },
226
+
227
+ // Hotjar Analytics (only one tag can be set)
228
+ hotjar: {
229
+ id: 1000000,
230
+ // Optional overrides for the script url, snippet version and async flag
231
+ // script: 'https://static.hotjar.com/c/hotjar-',
232
+ // version: 6,
233
+ // async: 1,
234
+ },
235
+
236
+ // Full story Analytics (only one tag can be set)
237
+ fullStory: {
238
+ org: 'X-XXXXXX-XXX',
239
+ host: 'fullstory.com',
240
+ script: 'edge.fullstory.com/s/fs.js',
241
+ namespace: 'FS',
242
+ // You can also override the loader snippet (advanced)
243
+ // loader: '(function(m,n,e,t,l,o,g,y){...})(...)',
244
+ },
245
+
246
+ // Unbounce conversion analytics
247
+ // Can also be enabled like so: `unbounce: true`
248
+ unbounce: {
249
+ enabled: true, // or false
250
+ // You can set a custom location or use the default one for unbounce
251
+ script: 'd3pkntwtp2ukl5.cloudfront.net/uba.js',
252
+ // You can also override the goal pushed to _ubaq (raw arguments array)
253
+ // goal: '["trackGoal", "convert"]',
254
+ },
255
+
256
+ // TikTok Pixel Analytics (only one tag can be set)
257
+ tiktok: {
258
+ id: 1000000,
259
+ // You can set a custom location or use the default one for TikTok
260
+ script: 'analytics.tiktok.com/i18n/pixel/events.js',
261
+ // You can also override the registered pixel methods and the page call
262
+ // methods: ['page', 'track', 'identify', '...'],
263
+ // page: 'ttq.page()',
264
+ },
265
+
266
+ // SimpleAnalytics
267
+ simpleanalytics: {
268
+ enabled: true, // or false
269
+ /**
270
+ * You can overwrite domain name (optional)
271
+ * @see https://docs.simpleanalytics.com/overwrite-domain-name
272
+ */
273
+ hostname: 'example.com',
274
+ /**
275
+ * You can configure a proxy (optional)
276
+ * @see https://docs.simpleanalytics.com/proxy
277
+ */
278
+ script: 'https://example.com/proxy.js',
279
+ noScript: 'https://example.com/simple/noscript.gif',
280
+ // You can also toggle the script tag attributes
281
+ // async: true,
282
+ // defer: true,
283
+ },
284
+
285
+ // Posthog
286
+ posthog: {
287
+ enabled: true, // or false
288
+ token: 'phc_XXXXXXXXXXXXXXXXXXXXXXXX', // Find this on https://us.posthog.com/project/settings/project-details#variables
289
+ api_host: 'https://us.i.posthog.com',
290
+
291
+ // Optional configuration passed to the PostHog initialization script
292
+ // NOTE: Because we're marshalling the config into a string, we can't support all of the options
293
+ // namely the ones that are functions.
294
+ // @see https://posthog.com/docs/libraries/js#config
295
+ //
296
+ // If you need support for more options, you will need to configure PostHog manually.
297
+ config: {},
298
+
299
+ // You can also override the loader snippet (advanced)
300
+ // loader: '!function(t,e){...}(document,window.posthog||[]);',
301
+ },
302
+
303
+ // Plausible
304
+ plausible: {
305
+ enabled: true, // or false
306
+ /**
307
+ * You can overwrite domain name to send stats to multiple Plausible dashboards (optional)
308
+ * @see https://plausible.io/docs/plausible-script#can-i-send-stats-to-multiple-dashboards-at-the-same-time
309
+ */
310
+ hostname: 'example.com',
311
+ /**
312
+ * You can configure a proxy (optional)
313
+ * @see https://plausible.io/docs/proxy/introduction
314
+ */
315
+ script: 'example.com/js/script.js',
316
+ // You can also toggle the script tag `defer` attribute
317
+ // defer: true,
318
+ },
319
+ })
320
+ ],
321
+ }
322
+ ```
323
+
324
+ ## Resources
325
+
326
+ - https://developers.google.com/analytics/devguides/collection/ga4
327
+ - https://developers.google.com/tag-manager/quickstart
328
+ - https://developers.facebook.com/docs/facebook-pixel/implementation
329
+ - https://www.linkedin.com/help/lms/answer/a427660
330
+ - https://yandex.com/support/metrica/quick-start.html
331
+ - https://tongji.baidu.com/open/api/more
332
+ - https://vk.com/faq14080
333
+ - https://help.ads.microsoft.com/#apex/ads/en/ext60065/
334
+ - https://help.hotjar.com/hc/en-us/articles/115009336727-How-to-Install-Your-Hotjar-Tracking-Code
335
+ - https://help.fullstory.com/hc/en-us/articles/360020623514-Installing-the-FullStory-Script#:~:text=Install%20your%20snippet%20directly%20on,closing%20tag.
336
+ - https://documentation.unbounce.com/hc/en-us/articles/203879180-Setting-Conversion-Goals-in-the-Classic-Builder
337
+ - https://posthog.com/docs/libraries/js
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ const defaults = {
4
+ source: "https://www.googletagmanager.com",
5
+ basePath: "/gtag/js",
6
+ async: true,
7
+ loader: "window.dataLayer = window.dataLayer || [];\nfunction gtag(){dataLayer.push(arguments);}\ngtag('js', new Date());\n"
8
+ };
9
+
10
+ function injectTag(options) {
11
+ const tags = [];
12
+ let properties = [];
13
+ if (Array.isArray(options)) {
14
+ properties.push(
15
+ ...options
16
+ );
17
+ } else {
18
+ properties.push(options);
19
+ }
20
+ properties = properties.filter((property) => Boolean(property.id));
21
+ if (!properties.length)
22
+ return tags;
23
+ const mainProperty = { ...defaults, ...properties.shift() };
24
+ if (!mainProperty)
25
+ return tags;
26
+ let template = "";
27
+ if (mainProperty.disable)
28
+ template += `window['ga-disable-${mainProperty.id}'] = true;
29
+ `;
30
+ for (const property of properties) {
31
+ if (property.disable)
32
+ template += `window['ga-disable-${property.id}'] = true;
33
+ `;
34
+ }
35
+ template += mainProperty.loader;
36
+ if (mainProperty.consentDefaults)
37
+ template += `gtag('consent', 'default', ${JSON.stringify(mainProperty.consentDefaults)});
38
+ `;
39
+ for (const property of [mainProperty, ...properties]) {
40
+ if (property.config || property.persistentValues) {
41
+ const config = Object.assign(
42
+ {},
43
+ property.persistentValues,
44
+ property.config
45
+ );
46
+ template += `gtag('config', '${property.id}', ${JSON.stringify(config)});
47
+ `;
48
+ } else {
49
+ template += `gtag('config', '${property.id}');
50
+ `;
51
+ }
52
+ }
53
+ tags.push({
54
+ tag: "script",
55
+ attrs: {
56
+ src: `${mainProperty.source}${mainProperty.basePath}?id=${mainProperty.id}`,
57
+ async: mainProperty.async
58
+ },
59
+ injectTo: mainProperty.injectTo
60
+ });
61
+ tags.push({
62
+ tag: "script",
63
+ children: template,
64
+ injectTo: mainProperty.injectTo
65
+ });
66
+ return tags;
67
+ }
68
+
69
+ exports.default = injectTag;
@@ -0,0 +1,67 @@
1
+ const defaults = {
2
+ source: "https://www.googletagmanager.com",
3
+ basePath: "/gtag/js",
4
+ async: true,
5
+ loader: "window.dataLayer = window.dataLayer || [];\nfunction gtag(){dataLayer.push(arguments);}\ngtag('js', new Date());\n"
6
+ };
7
+
8
+ function injectTag(options) {
9
+ const tags = [];
10
+ let properties = [];
11
+ if (Array.isArray(options)) {
12
+ properties.push(
13
+ ...options
14
+ );
15
+ } else {
16
+ properties.push(options);
17
+ }
18
+ properties = properties.filter((property) => Boolean(property.id));
19
+ if (!properties.length)
20
+ return tags;
21
+ const mainProperty = { ...defaults, ...properties.shift() };
22
+ if (!mainProperty)
23
+ return tags;
24
+ let template = "";
25
+ if (mainProperty.disable)
26
+ template += `window['ga-disable-${mainProperty.id}'] = true;
27
+ `;
28
+ for (const property of properties) {
29
+ if (property.disable)
30
+ template += `window['ga-disable-${property.id}'] = true;
31
+ `;
32
+ }
33
+ template += mainProperty.loader;
34
+ if (mainProperty.consentDefaults)
35
+ template += `gtag('consent', 'default', ${JSON.stringify(mainProperty.consentDefaults)});
36
+ `;
37
+ for (const property of [mainProperty, ...properties]) {
38
+ if (property.config || property.persistentValues) {
39
+ const config = Object.assign(
40
+ {},
41
+ property.persistentValues,
42
+ property.config
43
+ );
44
+ template += `gtag('config', '${property.id}', ${JSON.stringify(config)});
45
+ `;
46
+ } else {
47
+ template += `gtag('config', '${property.id}');
48
+ `;
49
+ }
50
+ }
51
+ tags.push({
52
+ tag: "script",
53
+ attrs: {
54
+ src: `${mainProperty.source}${mainProperty.basePath}?id=${mainProperty.id}`,
55
+ async: mainProperty.async
56
+ },
57
+ injectTo: mainProperty.injectTo
58
+ });
59
+ tags.push({
60
+ tag: "script",
61
+ children: template,
62
+ injectTo: mainProperty.injectTo
63
+ });
64
+ return tags;
65
+ }
66
+
67
+ export { injectTag as default };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const defaults = {
4
+ script: "https://static.hotjar.com/c/hotjar-",
5
+ version: 6,
6
+ async: 1
7
+ };
8
+
9
+ function injectTag(options) {
10
+ const tags = [];
11
+ if (!options.id)
12
+ return tags;
13
+ const { id, script, version, async } = { ...defaults, ...options };
14
+ let template = "";
15
+ template += "(function(h,o,t,j,a,r){";
16
+ template += "h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};";
17
+ template += `h._hjSettings={hjid:${id},hjsv:${version}};`;
18
+ template += 'a=o.getElementsByTagName("head")[0];';
19
+ template += `r=o.createElement("script");r.async=${async};`;
20
+ template += "r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;";
21
+ template += "a.appendChild(r);";
22
+ template += `})(window,document,'${script}','.js?sv=');`;
23
+ tags.push({
24
+ tag: "script",
25
+ children: template
26
+ });
27
+ return tags;
28
+ }
29
+
30
+ exports.default = injectTag;
@@ -0,0 +1,28 @@
1
+ const defaults = {
2
+ script: "https://static.hotjar.com/c/hotjar-",
3
+ version: 6,
4
+ async: 1
5
+ };
6
+
7
+ function injectTag(options) {
8
+ const tags = [];
9
+ if (!options.id)
10
+ return tags;
11
+ const { id, script, version, async } = { ...defaults, ...options };
12
+ let template = "";
13
+ template += "(function(h,o,t,j,a,r){";
14
+ template += "h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};";
15
+ template += `h._hjSettings={hjid:${id},hjsv:${version}};`;
16
+ template += 'a=o.getElementsByTagName("head")[0];';
17
+ template += `r=o.createElement("script");r.async=${async};`;
18
+ template += "r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;";
19
+ template += "a.appendChild(r);";
20
+ template += `})(window,document,'${script}','.js?sv=');`;
21
+ tags.push({
22
+ tag: "script",
23
+ children: template
24
+ });
25
+ return tags;
26
+ }
27
+
28
+ export { injectTag as default };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const loader = `(function(m,n,e,t,l,o,g,y){if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src='https://'+_fs_script;y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};g.anonymize=function(){g.identify(!!0)};g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};g.log = function(a,b){g("log",[a,b])};g.consent=function(a){g("consent",!arguments.length||a)};g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};g.clearUserCookie=function(){};g.setVars=function(n, p){g('setVars',[n,p]);};g._w={};y='XMLHttpRequest';g._w[y]=m[y];y='fetch';g._w[y]=m[y];if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)};g._v="1.3.0";})(window,document,window['_fs_namespace'],'script','user');`;
4
+ const defaults = {
5
+ host: "fullstory.com",
6
+ script: "edge.fullstory.com/s/fs.js",
7
+ namespace: "FS",
8
+ loader
9
+ };
10
+
11
+ function injectTag(options) {
12
+ const tags = [];
13
+ const fullOptions = { ...defaults, ...options };
14
+ if (!fullOptions.org)
15
+ return tags;
16
+ let template = "";
17
+ template += `window['_fs_host'] = '${fullOptions.host}';`;
18
+ template += `window['_fs_script'] = '${fullOptions.script}';`;
19
+ template += `window['_fs_org'] = '${fullOptions.org}';`;
20
+ template += `window['_fs_namespace'] = '${fullOptions.namespace}';`;
21
+ template += fullOptions.loader;
22
+ tags.push({
23
+ tag: "script",
24
+ children: template
25
+ });
26
+ return tags;
27
+ }
28
+
29
+ exports.default = injectTag;
@@ -0,0 +1,27 @@
1
+ const loader = `(function(m,n,e,t,l,o,g,y){if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src='https://'+_fs_script;y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};g.anonymize=function(){g.identify(!!0)};g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};g.log = function(a,b){g("log",[a,b])};g.consent=function(a){g("consent",!arguments.length||a)};g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};g.clearUserCookie=function(){};g.setVars=function(n, p){g('setVars',[n,p]);};g._w={};y='XMLHttpRequest';g._w[y]=m[y];y='fetch';g._w[y]=m[y];if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)};g._v="1.3.0";})(window,document,window['_fs_namespace'],'script','user');`;
2
+ const defaults = {
3
+ host: "fullstory.com",
4
+ script: "edge.fullstory.com/s/fs.js",
5
+ namespace: "FS",
6
+ loader
7
+ };
8
+
9
+ function injectTag(options) {
10
+ const tags = [];
11
+ const fullOptions = { ...defaults, ...options };
12
+ if (!fullOptions.org)
13
+ return tags;
14
+ let template = "";
15
+ template += `window['_fs_host'] = '${fullOptions.host}';`;
16
+ template += `window['_fs_script'] = '${fullOptions.script}';`;
17
+ template += `window['_fs_org'] = '${fullOptions.org}';`;
18
+ template += `window['_fs_namespace'] = '${fullOptions.namespace}';`;
19
+ template += fullOptions.loader;
20
+ tags.push({
21
+ tag: "script",
22
+ children: template
23
+ });
24
+ return tags;
25
+ }
26
+
27
+ export { injectTag as default };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const defaults = {
4
+ script: "d3pkntwtp2ukl5.cloudfront.net/uba.js",
5
+ goal: '["trackGoal", "convert"]'
6
+ };
7
+
8
+ function injectTag(options) {
9
+ const tags = [];
10
+ const { script: sourceLocation, goal } = typeof options === "object" ? { ...defaults, ...options } : defaults;
11
+ let template = "";
12
+ template += "var _ubaq = _ubaq || [];";
13
+ template += `_ubaq.push(${goal});`;
14
+ template += "(function () {";
15
+ template += 'var ub_script = document.createElement("script");';
16
+ template += 'ub_script.type = "text/javascript";';
17
+ template += `ub_script.src = ("https:" == document.location.protocol ? "https://" : "http://") + "${sourceLocation}";`;
18
+ template += 'var s = document.getElementsByTagName("script")[0];';
19
+ template += "s.parentNode.insertBefore(ub_script, s);";
20
+ template += "})();";
21
+ tags.push({
22
+ tag: "script",
23
+ children: template
24
+ });
25
+ return tags;
26
+ }
27
+
28
+ exports.default = injectTag;
@@ -0,0 +1,26 @@
1
+ const defaults = {
2
+ script: "d3pkntwtp2ukl5.cloudfront.net/uba.js",
3
+ goal: '["trackGoal", "convert"]'
4
+ };
5
+
6
+ function injectTag(options) {
7
+ const tags = [];
8
+ const { script: sourceLocation, goal } = typeof options === "object" ? { ...defaults, ...options } : defaults;
9
+ let template = "";
10
+ template += "var _ubaq = _ubaq || [];";
11
+ template += `_ubaq.push(${goal});`;
12
+ template += "(function () {";
13
+ template += 'var ub_script = document.createElement("script");';
14
+ template += 'ub_script.type = "text/javascript";';
15
+ template += `ub_script.src = ("https:" == document.location.protocol ? "https://" : "http://") + "${sourceLocation}";`;
16
+ template += 'var s = document.getElementsByTagName("script")[0];';
17
+ template += "s.parentNode.insertBefore(ub_script, s);";
18
+ template += "})();";
19
+ tags.push({
20
+ tag: "script",
21
+ children: template
22
+ });
23
+ return tags;
24
+ }
25
+
26
+ export { injectTag as default };