@c15t/scripts 1.0.1 → 1.1.0-rc.1

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.
Files changed (59) hide show
  1. package/dist/databuddy.cjs +105 -50
  2. package/dist/databuddy.js +99 -47
  3. package/dist/engine/compile.cjs +126 -0
  4. package/dist/engine/compile.js +89 -0
  5. package/dist/engine/runtime.cjs +379 -0
  6. package/dist/engine/runtime.js +345 -0
  7. package/dist/google-tag-manager.cjs +80 -96
  8. package/dist/google-tag-manager.js +74 -87
  9. package/dist/google-tag.cjs +88 -39
  10. package/dist/google-tag.js +82 -36
  11. package/dist/linkedin-insights.cjs +52 -41
  12. package/dist/linkedin-insights.js +45 -37
  13. package/dist/meta-pixel.cjs +92 -26
  14. package/dist/meta-pixel.js +86 -23
  15. package/dist/microsoft-uet.cjs +92 -52
  16. package/dist/microsoft-uet.js +86 -49
  17. package/dist/posthog.cjs +102 -53
  18. package/dist/posthog.js +96 -50
  19. package/dist/resolve.cjs +67 -0
  20. package/dist/resolve.js +33 -0
  21. package/dist/tiktok-pixel.cjs +93 -27
  22. package/dist/tiktok-pixel.js +86 -23
  23. package/dist/types.cjs +47 -0
  24. package/dist/types.js +7 -0
  25. package/dist/x-pixel.cjs +49 -19
  26. package/dist/x-pixel.js +42 -15
  27. package/dist-types/databuddy.d.ts +144 -0
  28. package/dist-types/engine/compile.d.ts +3 -0
  29. package/dist-types/engine/runtime.d.ts +3 -0
  30. package/dist-types/engine.test.d.ts +1 -0
  31. package/dist-types/google-tag-manager.d.ts +97 -0
  32. package/dist-types/google-tag.d.ts +96 -0
  33. package/dist-types/helpers.test.d.ts +1 -0
  34. package/dist-types/linkedin-insights.d.ts +79 -0
  35. package/{dist → dist-types}/meta-pixel.d.ts +61 -14
  36. package/dist-types/microsoft-uet.d.ts +94 -0
  37. package/dist-types/posthog.d.ts +112 -0
  38. package/dist-types/resolve.d.ts +9 -0
  39. package/dist-types/tiktok-pixel.d.ts +91 -0
  40. package/dist-types/types.d.ts +259 -0
  41. package/{dist → dist-types}/x-pixel.d.ts +38 -12
  42. package/package.json +46 -45
  43. package/LICENSE.md +0 -595
  44. package/dist/databuddy.d.ts +0 -104
  45. package/dist/databuddy.d.ts.map +0 -1
  46. package/dist/google-tag-manager.d.ts +0 -63
  47. package/dist/google-tag-manager.d.ts.map +0 -1
  48. package/dist/google-tag.d.ts +0 -38
  49. package/dist/google-tag.d.ts.map +0 -1
  50. package/dist/linkedin-insights.d.ts +0 -48
  51. package/dist/linkedin-insights.d.ts.map +0 -1
  52. package/dist/meta-pixel.d.ts.map +0 -1
  53. package/dist/microsoft-uet.d.ts +0 -40
  54. package/dist/microsoft-uet.d.ts.map +0 -1
  55. package/dist/posthog.d.ts +0 -54
  56. package/dist/posthog.d.ts.map +0 -1
  57. package/dist/tiktok-pixel.d.ts +0 -44
  58. package/dist/tiktok-pixel.d.ts.map +0 -1
  59. package/dist/x-pixel.d.ts.map +0 -1
@@ -1,93 +1,80 @@
1
- const DEFAULT_GTM_CONSENT_CONFIG = {
2
- functionality_storage: 'denied',
3
- security_storage: 'denied',
4
- analytics_storage: 'denied',
5
- ad_storage: 'denied',
6
- ad_user_data: 'denied',
7
- ad_personalization: 'denied',
8
- personalization_storage: 'denied'
9
- };
10
- const CONSENT_STATE_TO_GTM_MAPPING = {
11
- necessary: [
12
- 'security_storage'
13
- ],
14
- functionality: [
15
- 'functionality_storage'
1
+ import { resolveManifest } from "./resolve.js";
2
+ import { vendorManifestContract } from "./types.js";
3
+ const googleTagManagerManifest = {
4
+ ...vendorManifestContract,
5
+ vendor: 'google-tag-manager',
6
+ category: 'necessary',
7
+ alwaysLoad: true,
8
+ bootstrap: [
9
+ {
10
+ type: 'setGlobal',
11
+ name: 'dataLayer',
12
+ value: [],
13
+ ifUndefined: true
14
+ },
15
+ {
16
+ type: 'defineQueueFunction',
17
+ name: 'gtag',
18
+ queue: 'dataLayer',
19
+ ifUndefined: true
20
+ }
16
21
  ],
17
- measurement: [
18
- 'analytics_storage'
22
+ install: [
23
+ {
24
+ type: 'pushToQueue',
25
+ queue: 'dataLayer',
26
+ value: {
27
+ 'gtm.start': '{{loadTime}}',
28
+ event: 'gtm.js'
29
+ }
30
+ },
31
+ {
32
+ type: 'loadScript',
33
+ src: 'https://www.googletagmanager.com/gtm.js?id={{id}}',
34
+ async: true
35
+ }
19
36
  ],
20
- marketing: [
21
- 'ad_storage',
22
- 'ad_user_data',
23
- 'ad_personalization'
37
+ onConsentChange: [
38
+ {
39
+ type: 'callGlobal',
40
+ global: 'gtag',
41
+ args: [
42
+ 'event',
43
+ '{{updateEventName}}'
44
+ ]
45
+ }
24
46
  ],
25
- experience: [
26
- 'personalization_storage'
27
- ]
47
+ consentMapping: {
48
+ necessary: [
49
+ 'security_storage'
50
+ ],
51
+ functionality: [
52
+ 'functionality_storage'
53
+ ],
54
+ measurement: [
55
+ 'analytics_storage'
56
+ ],
57
+ marketing: [
58
+ 'ad_storage',
59
+ 'ad_user_data',
60
+ 'ad_personalization'
61
+ ],
62
+ experience: [
63
+ 'personalization_storage'
64
+ ]
65
+ },
66
+ consentSignal: 'gtag'
28
67
  };
29
- function mapConsentStateToGTM(consentState) {
30
- const gtmConfig = {
31
- ...DEFAULT_GTM_CONSENT_CONFIG
32
- };
33
- for (const consentType of Object.keys(consentState)){
34
- const isGranted = consentState[consentType];
35
- const gtmConsentTypes = CONSENT_STATE_TO_GTM_MAPPING[consentType];
36
- for (const gtmType of gtmConsentTypes)gtmConfig[gtmType] = isGranted ? 'granted' : 'denied';
37
- }
38
- return gtmConfig;
39
- }
40
- function googleTagManager({ id, script, updateEventName }) {
41
- return {
42
- ...script,
43
- id: script?.id ? script.id : 'google-tag-manager',
44
- src: script?.src ? script.src : `https://www.googletagmanager.com/gtm.js?id=${id}`,
45
- category: script?.category ?? 'necessary',
46
- async: script?.async ?? true,
47
- alwaysLoad: true,
48
- onBeforeLoad: ({ consents, elementId, ...rest })=>{
49
- const gtmConsent = consents ? mapConsentStateToGTM(consents) : DEFAULT_GTM_CONSENT_CONFIG;
50
- const setupScript = document.createElement("script");
51
- setupScript.id = `${elementId}-init`;
52
- setupScript.textContent = `
53
- window.dataLayer = window.dataLayer || [];
54
- window.gtag = function gtag() {
55
- window.dataLayer.push(arguments);
56
- };
57
- window.gtag('consent', 'default', {
58
- ...${JSON.stringify(gtmConsent)},
68
+ function googleTagManager({ id, updateEventName, consentMapping }) {
69
+ const manifest = consentMapping ? {
70
+ ...googleTagManagerManifest,
71
+ consentMapping
72
+ } : googleTagManagerManifest;
73
+ const resolved = resolveManifest(manifest, {
74
+ id,
75
+ loadTime: Date.now(),
76
+ updateEventName: updateEventName ?? 'consent-update'
59
77
  });
60
- window.dataLayer.push({
61
- 'gtm.start': Date.now(),
62
- event: 'gtm.js',
63
- });
64
- `;
65
- if (!document.head) throw new Error("Document head is not available for script injection");
66
- document.head.appendChild(setupScript);
67
- if (script?.onBeforeLoad) script.onBeforeLoad({
68
- consents,
69
- elementId,
70
- ...rest
71
- });
72
- },
73
- onDelete: ({ elementId, ...rest })=>{
74
- const setupScript = document.getElementById(`${elementId}-init`);
75
- if (setupScript) setupScript.remove();
76
- if (script?.onDelete) script.onDelete({
77
- elementId,
78
- ...rest
79
- });
80
- },
81
- onConsentChange ({ consents, ...rest }) {
82
- if (window.gtag) {
83
- window.gtag('consent', 'update', mapConsentStateToGTM(consents));
84
- window.gtag('event', updateEventName ?? 'consent-update');
85
- }
86
- if (script?.onConsentChange) script.onConsentChange({
87
- consents,
88
- ...rest
89
- });
90
- }
91
- };
78
+ return resolved;
92
79
  }
93
- export { DEFAULT_GTM_CONSENT_CONFIG, googleTagManager, mapConsentStateToGTM };
80
+ export { googleTagManager, googleTagManagerManifest };
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
13
13
  })();
14
14
  (()=>{
15
15
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
19
19
  Object.defineProperty(exports1, '__esModule', {
@@ -24,52 +24,101 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
+ gtagManifest: ()=>gtagManifest,
27
28
  gtag: ()=>gtag
28
29
  });
29
- const external_google_tag_manager_cjs_namespaceObject = require("./google-tag-manager.cjs");
30
- function gtag({ id, script, category }) {
30
+ const external_resolve_cjs_namespaceObject = require("./resolve.cjs");
31
+ const external_types_cjs_namespaceObject = require("./types.cjs");
32
+ const gtagManifest = {
33
+ ...external_types_cjs_namespaceObject.vendorManifestContract,
34
+ vendor: 'gtag',
35
+ category: '{{category}}',
36
+ alwaysLoad: true,
37
+ persistAfterConsentRevoked: true,
38
+ bootstrap: [
39
+ {
40
+ type: 'setGlobal',
41
+ name: 'dataLayer',
42
+ value: [],
43
+ ifUndefined: true
44
+ },
45
+ {
46
+ type: 'defineQueueFunction',
47
+ name: 'gtag',
48
+ queue: 'dataLayer',
49
+ ifUndefined: true
50
+ }
51
+ ],
52
+ install: [
53
+ {
54
+ type: 'callGlobal',
55
+ global: 'gtag',
56
+ args: [
57
+ 'js',
58
+ '{{loadTime}}'
59
+ ]
60
+ },
61
+ {
62
+ type: 'callGlobal',
63
+ global: 'gtag',
64
+ args: [
65
+ 'config',
66
+ '{{id}}'
67
+ ]
68
+ },
69
+ {
70
+ type: 'loadScript',
71
+ src: 'https://www.googletagmanager.com/gtag/js?id={{id}}',
72
+ async: true
73
+ }
74
+ ],
75
+ consentMapping: {
76
+ necessary: [
77
+ 'security_storage'
78
+ ],
79
+ functionality: [
80
+ 'functionality_storage'
81
+ ],
82
+ measurement: [
83
+ 'analytics_storage'
84
+ ],
85
+ marketing: [
86
+ 'ad_storage',
87
+ 'ad_user_data',
88
+ 'ad_personalization'
89
+ ],
90
+ experience: [
91
+ 'personalization_storage'
92
+ ]
93
+ },
94
+ consentSignal: 'gtag'
95
+ };
96
+ function gtag({ id, category, consentMapping, script }) {
97
+ const manifest = consentMapping ? {
98
+ ...gtagManifest,
99
+ consentMapping
100
+ } : gtagManifest;
101
+ const resolved = (0, external_resolve_cjs_namespaceObject.resolveManifest)(manifest, {
102
+ id,
103
+ category,
104
+ loadTime: new Date()
105
+ });
106
+ if (!script) return resolved;
31
107
  return {
108
+ ...resolved,
32
109
  ...script,
33
- id: script?.id ? script.id : 'gtag',
34
- src: script?.src ? script.src : `https://www.googletagmanager.com/gtag/js?id=${id}`,
35
- category: category,
36
- async: script?.async ?? true,
37
- persistAfterConsentRevoked: true,
38
- alwaysLoad: true,
39
- onBeforeLoad: ({ consents, elementId, ...rest })=>{
40
- let gtmConsent = external_google_tag_manager_cjs_namespaceObject.DEFAULT_GTM_CONSENT_CONFIG;
41
- if (consents) gtmConsent = (0, external_google_tag_manager_cjs_namespaceObject.mapConsentStateToGTM)(consents);
42
- const setupScript = document.createElement("script");
43
- setupScript.id = `${elementId}-init`;
44
- setupScript.textContent = `
45
- window.dataLayer = window.dataLayer || [];
46
- window.gtag = function gtag() {
47
- window.dataLayer.push(arguments);
48
- };
49
- window.gtag('consent', 'default', {
50
- ...${JSON.stringify(gtmConsent)},
51
- });
52
- window.gtag('js', new Date());
53
- window.gtag('config', '${id}');
54
- `;
55
- if (!document.head) throw new Error("Document head is not available for script injection");
56
- document.head.appendChild(setupScript);
57
- if (script?.onBeforeLoad) script.onBeforeLoad({
58
- consents,
59
- elementId,
60
- ...rest
61
- });
62
- },
63
- onConsentChange (args) {
64
- if (window.gtag) window.gtag('consent', 'update', (0, external_google_tag_manager_cjs_namespaceObject.mapConsentStateToGTM)(args.consents));
65
- if (script?.onConsentChange) script.onConsentChange(args);
110
+ attributes: {
111
+ ...resolved.attributes ?? {},
112
+ ...script.attributes ?? {}
66
113
  }
67
114
  };
68
115
  }
69
116
  exports.gtag = __webpack_exports__.gtag;
70
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
71
- "gtag"
72
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
117
+ exports.gtagManifest = __webpack_exports__.gtagManifest;
118
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
119
+ "gtag",
120
+ "gtagManifest"
121
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
73
122
  Object.defineProperty(exports, '__esModule', {
74
123
  value: true
75
124
  });
@@ -1,41 +1,87 @@
1
- import { DEFAULT_GTM_CONSENT_CONFIG, mapConsentStateToGTM } from "./google-tag-manager.js";
2
- function gtag({ id, script, category }) {
1
+ import { resolveManifest } from "./resolve.js";
2
+ import { vendorManifestContract } from "./types.js";
3
+ const gtagManifest = {
4
+ ...vendorManifestContract,
5
+ vendor: 'gtag',
6
+ category: '{{category}}',
7
+ alwaysLoad: true,
8
+ persistAfterConsentRevoked: true,
9
+ bootstrap: [
10
+ {
11
+ type: 'setGlobal',
12
+ name: 'dataLayer',
13
+ value: [],
14
+ ifUndefined: true
15
+ },
16
+ {
17
+ type: 'defineQueueFunction',
18
+ name: 'gtag',
19
+ queue: 'dataLayer',
20
+ ifUndefined: true
21
+ }
22
+ ],
23
+ install: [
24
+ {
25
+ type: 'callGlobal',
26
+ global: 'gtag',
27
+ args: [
28
+ 'js',
29
+ '{{loadTime}}'
30
+ ]
31
+ },
32
+ {
33
+ type: 'callGlobal',
34
+ global: 'gtag',
35
+ args: [
36
+ 'config',
37
+ '{{id}}'
38
+ ]
39
+ },
40
+ {
41
+ type: 'loadScript',
42
+ src: 'https://www.googletagmanager.com/gtag/js?id={{id}}',
43
+ async: true
44
+ }
45
+ ],
46
+ consentMapping: {
47
+ necessary: [
48
+ 'security_storage'
49
+ ],
50
+ functionality: [
51
+ 'functionality_storage'
52
+ ],
53
+ measurement: [
54
+ 'analytics_storage'
55
+ ],
56
+ marketing: [
57
+ 'ad_storage',
58
+ 'ad_user_data',
59
+ 'ad_personalization'
60
+ ],
61
+ experience: [
62
+ 'personalization_storage'
63
+ ]
64
+ },
65
+ consentSignal: 'gtag'
66
+ };
67
+ function gtag({ id, category, consentMapping, script }) {
68
+ const manifest = consentMapping ? {
69
+ ...gtagManifest,
70
+ consentMapping
71
+ } : gtagManifest;
72
+ const resolved = resolveManifest(manifest, {
73
+ id,
74
+ category,
75
+ loadTime: new Date()
76
+ });
77
+ if (!script) return resolved;
3
78
  return {
79
+ ...resolved,
4
80
  ...script,
5
- id: script?.id ? script.id : 'gtag',
6
- src: script?.src ? script.src : `https://www.googletagmanager.com/gtag/js?id=${id}`,
7
- category: category,
8
- async: script?.async ?? true,
9
- persistAfterConsentRevoked: true,
10
- alwaysLoad: true,
11
- onBeforeLoad: ({ consents, elementId, ...rest })=>{
12
- let gtmConsent = DEFAULT_GTM_CONSENT_CONFIG;
13
- if (consents) gtmConsent = mapConsentStateToGTM(consents);
14
- const setupScript = document.createElement("script");
15
- setupScript.id = `${elementId}-init`;
16
- setupScript.textContent = `
17
- window.dataLayer = window.dataLayer || [];
18
- window.gtag = function gtag() {
19
- window.dataLayer.push(arguments);
20
- };
21
- window.gtag('consent', 'default', {
22
- ...${JSON.stringify(gtmConsent)},
23
- });
24
- window.gtag('js', new Date());
25
- window.gtag('config', '${id}');
26
- `;
27
- if (!document.head) throw new Error("Document head is not available for script injection");
28
- document.head.appendChild(setupScript);
29
- if (script?.onBeforeLoad) script.onBeforeLoad({
30
- consents,
31
- elementId,
32
- ...rest
33
- });
34
- },
35
- onConsentChange (args) {
36
- if (window.gtag) window.gtag('consent', 'update', mapConsentStateToGTM(args.consents));
37
- if (script?.onConsentChange) script.onConsentChange(args);
81
+ attributes: {
82
+ ...resolved.attributes ?? {},
83
+ ...script.attributes ?? {}
38
84
  }
39
85
  };
40
86
  }
41
- export { gtag };
87
+ export { gtag, gtagManifest };
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
13
13
  })();
14
14
  (()=>{
15
15
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
19
19
  Object.defineProperty(exports1, '__esModule', {
@@ -24,51 +24,62 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- linkedinInsights: ()=>linkedinInsights
27
+ linkedinInsights: ()=>linkedinInsights,
28
+ linkedinInsightsManifest: ()=>linkedinInsightsManifest
28
29
  });
29
- function linkedinInsights({ id, script }) {
30
- const category = script?.category ?? 'marketing';
31
- return {
32
- id: script?.id ?? 'linkedin-insights',
33
- category,
34
- textContent: `
35
- (function(l) {
36
- if (!l){window.lintrk = function(a,b){window.lintrk.q.push([a,b])};
37
- window.lintrk.q=[]}
38
- var s = document.getElementsByTagName("script")[0];
39
- var b = document.createElement("script");
40
- b.type = "text/javascript";b.async = true;
41
- b.src = "${script?.src ?? 'https://snap.licdn.com/li.lms-analytics/insight.min.js'}";
42
- s.parentNode.insertBefore(b, s);})(window.lintrk);
43
- `.trim(),
44
- onBeforeLoad ({ elementId, ...rest }) {
45
- const setupScript = document.createElement("script");
46
- setupScript.id = `${elementId}-init`;
47
- setupScript.textContent = `
48
- _linkedin_partner_id = "${id}";
49
- window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
50
- window._linkedin_data_partner_ids.push(_linkedin_partner_id);
51
- `;
52
- if (!document.head) throw new Error("Document head is not available for script injection");
53
- document.head.appendChild(setupScript);
54
- if (script?.onBeforeLoad) script.onBeforeLoad({
55
- elementId,
56
- ...rest
57
- });
30
+ const external_resolve_cjs_namespaceObject = require("./resolve.cjs");
31
+ const external_types_cjs_namespaceObject = require("./types.cjs");
32
+ const linkedinInsightsManifest = {
33
+ ...external_types_cjs_namespaceObject.vendorManifestContract,
34
+ vendor: 'linkedin-insights',
35
+ category: 'marketing',
36
+ install: [
37
+ {
38
+ type: 'setGlobal',
39
+ name: '_linkedin_partner_id',
40
+ value: '{{id}}',
41
+ ifUndefined: false
58
42
  },
59
- onDelete ({ elementId, ...rest }) {
60
- if (window.ORIBILI && 'function' == typeof window.ORIBILI._DEBUG?.disableScript) window.ORIBILI._DEBUG.disableScript();
61
- if (script?.onDelete) script.onDelete({
62
- elementId,
63
- ...rest
64
- });
43
+ {
44
+ type: 'setGlobal',
45
+ name: '_linkedin_data_partner_ids',
46
+ value: [],
47
+ ifUndefined: true
48
+ },
49
+ {
50
+ type: 'pushToQueue',
51
+ queue: '_linkedin_data_partner_ids',
52
+ value: '{{id}}'
53
+ },
54
+ {
55
+ type: 'defineStubFunction',
56
+ name: 'lintrk',
57
+ queue: {
58
+ property: 'q'
59
+ },
60
+ queueFormat: 'array',
61
+ ifUndefined: true
62
+ },
63
+ {
64
+ type: 'loadScript',
65
+ src: "{{scriptSrc}}",
66
+ async: true
65
67
  }
66
- };
68
+ ]
69
+ };
70
+ function linkedinInsights({ id, scriptSrc }) {
71
+ const resolved = (0, external_resolve_cjs_namespaceObject.resolveManifest)(linkedinInsightsManifest, {
72
+ id,
73
+ scriptSrc: scriptSrc ?? 'https://snap.licdn.com/li.lms-analytics/insight.min.js'
74
+ });
75
+ return resolved;
67
76
  }
68
77
  exports.linkedinInsights = __webpack_exports__.linkedinInsights;
69
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
70
- "linkedinInsights"
71
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
78
+ exports.linkedinInsightsManifest = __webpack_exports__.linkedinInsightsManifest;
79
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
80
+ "linkedinInsights",
81
+ "linkedinInsightsManifest"
82
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
72
83
  Object.defineProperty(exports, '__esModule', {
73
84
  value: true
74
85
  });
@@ -1,40 +1,48 @@
1
- function linkedinInsights({ id, script }) {
2
- const category = script?.category ?? 'marketing';
3
- return {
4
- id: script?.id ?? 'linkedin-insights',
5
- category,
6
- textContent: `
7
- (function(l) {
8
- if (!l){window.lintrk = function(a,b){window.lintrk.q.push([a,b])};
9
- window.lintrk.q=[]}
10
- var s = document.getElementsByTagName("script")[0];
11
- var b = document.createElement("script");
12
- b.type = "text/javascript";b.async = true;
13
- b.src = "${script?.src ?? 'https://snap.licdn.com/li.lms-analytics/insight.min.js'}";
14
- s.parentNode.insertBefore(b, s);})(window.lintrk);
15
- `.trim(),
16
- onBeforeLoad ({ elementId, ...rest }) {
17
- const setupScript = document.createElement("script");
18
- setupScript.id = `${elementId}-init`;
19
- setupScript.textContent = `
20
- _linkedin_partner_id = "${id}";
21
- window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
22
- window._linkedin_data_partner_ids.push(_linkedin_partner_id);
23
- `;
24
- if (!document.head) throw new Error("Document head is not available for script injection");
25
- document.head.appendChild(setupScript);
26
- if (script?.onBeforeLoad) script.onBeforeLoad({
27
- elementId,
28
- ...rest
29
- });
1
+ import { resolveManifest } from "./resolve.js";
2
+ import { vendorManifestContract } from "./types.js";
3
+ const linkedinInsightsManifest = {
4
+ ...vendorManifestContract,
5
+ vendor: 'linkedin-insights',
6
+ category: 'marketing',
7
+ install: [
8
+ {
9
+ type: 'setGlobal',
10
+ name: '_linkedin_partner_id',
11
+ value: '{{id}}',
12
+ ifUndefined: false
30
13
  },
31
- onDelete ({ elementId, ...rest }) {
32
- if (window.ORIBILI && 'function' == typeof window.ORIBILI._DEBUG?.disableScript) window.ORIBILI._DEBUG.disableScript();
33
- if (script?.onDelete) script.onDelete({
34
- elementId,
35
- ...rest
36
- });
14
+ {
15
+ type: 'setGlobal',
16
+ name: '_linkedin_data_partner_ids',
17
+ value: [],
18
+ ifUndefined: true
19
+ },
20
+ {
21
+ type: 'pushToQueue',
22
+ queue: '_linkedin_data_partner_ids',
23
+ value: '{{id}}'
24
+ },
25
+ {
26
+ type: 'defineStubFunction',
27
+ name: 'lintrk',
28
+ queue: {
29
+ property: 'q'
30
+ },
31
+ queueFormat: 'array',
32
+ ifUndefined: true
33
+ },
34
+ {
35
+ type: 'loadScript',
36
+ src: "{{scriptSrc}}",
37
+ async: true
37
38
  }
38
- };
39
+ ]
40
+ };
41
+ function linkedinInsights({ id, scriptSrc }) {
42
+ const resolved = resolveManifest(linkedinInsightsManifest, {
43
+ id,
44
+ scriptSrc: scriptSrc ?? 'https://snap.licdn.com/li.lms-analytics/insight.min.js'
45
+ });
46
+ return resolved;
39
47
  }
40
- export { linkedinInsights };
48
+ export { linkedinInsights, linkedinInsightsManifest };