@c15t/scripts 1.0.0-canary-20251012181938
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.md +595 -0
- package/README.md +70 -0
- package/dist/google-tag-manager.cjs +133 -0
- package/dist/google-tag-manager.d.ts +63 -0
- package/dist/google-tag-manager.d.ts.map +1 -0
- package/dist/google-tag-manager.js +93 -0
- package/dist/google-tag.cjs +75 -0
- package/dist/google-tag.d.ts +38 -0
- package/dist/google-tag.d.ts.map +1 -0
- package/dist/google-tag.js +41 -0
- package/dist/linkedin-insights.cjs +74 -0
- package/dist/linkedin-insights.d.ts +48 -0
- package/dist/linkedin-insights.d.ts.map +1 -0
- package/dist/linkedin-insights.js +40 -0
- package/dist/meta-pixel.cjs +63 -0
- package/dist/meta-pixel.d.ts +138 -0
- package/dist/meta-pixel.d.ts.map +1 -0
- package/dist/meta-pixel.js +26 -0
- package/dist/microsoft-uet.cjs +90 -0
- package/dist/microsoft-uet.d.ts +40 -0
- package/dist/microsoft-uet.d.ts.map +1 -0
- package/dist/microsoft-uet.js +56 -0
- package/dist/posthog.cjs +88 -0
- package/dist/posthog.d.ts +54 -0
- package/dist/posthog.d.ts.map +1 -0
- package/dist/posthog.js +54 -0
- package/dist/tiktok-pixel.cjs +60 -0
- package/dist/tiktok-pixel.d.ts +44 -0
- package/dist/tiktok-pixel.d.ts.map +1 -0
- package/dist/tiktok-pixel.js +26 -0
- package/dist/x-pixel.cjs +55 -0
- package/dist/x-pixel.d.ts +140 -0
- package/dist/x-pixel.d.ts.map +1 -0
- package/dist/x-pixel.js +18 -0
- package/package.json +46 -0
- package/readme.json +12 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
DEFAULT_GTM_CONSENT_CONFIG: ()=>DEFAULT_GTM_CONSENT_CONFIG,
|
|
28
|
+
googleTagManager: ()=>googleTagManager,
|
|
29
|
+
mapConsentStateToGTM: ()=>mapConsentStateToGTM
|
|
30
|
+
});
|
|
31
|
+
const DEFAULT_GTM_CONSENT_CONFIG = {
|
|
32
|
+
functionality_storage: 'denied',
|
|
33
|
+
security_storage: 'denied',
|
|
34
|
+
analytics_storage: 'denied',
|
|
35
|
+
ad_storage: 'denied',
|
|
36
|
+
ad_user_data: 'denied',
|
|
37
|
+
ad_personalization: 'denied',
|
|
38
|
+
personalization_storage: 'denied'
|
|
39
|
+
};
|
|
40
|
+
const CONSENT_STATE_TO_GTM_MAPPING = {
|
|
41
|
+
necessary: [
|
|
42
|
+
'security_storage'
|
|
43
|
+
],
|
|
44
|
+
functionality: [
|
|
45
|
+
'functionality_storage'
|
|
46
|
+
],
|
|
47
|
+
measurement: [
|
|
48
|
+
'analytics_storage'
|
|
49
|
+
],
|
|
50
|
+
marketing: [
|
|
51
|
+
'ad_storage',
|
|
52
|
+
'ad_user_data',
|
|
53
|
+
'ad_personalization'
|
|
54
|
+
],
|
|
55
|
+
experience: [
|
|
56
|
+
'personalization_storage'
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
function mapConsentStateToGTM(consentState) {
|
|
60
|
+
const gtmConfig = {
|
|
61
|
+
...DEFAULT_GTM_CONSENT_CONFIG
|
|
62
|
+
};
|
|
63
|
+
for (const consentType of Object.keys(consentState)){
|
|
64
|
+
const isGranted = consentState[consentType];
|
|
65
|
+
const gtmConsentTypes = CONSENT_STATE_TO_GTM_MAPPING[consentType];
|
|
66
|
+
for (const gtmType of gtmConsentTypes)gtmConfig[gtmType] = isGranted ? 'granted' : 'denied';
|
|
67
|
+
}
|
|
68
|
+
return gtmConfig;
|
|
69
|
+
}
|
|
70
|
+
function googleTagManager({ id, script, updateEventName }) {
|
|
71
|
+
return {
|
|
72
|
+
...script,
|
|
73
|
+
id: script?.id ? script.id : 'google-tag-manager',
|
|
74
|
+
src: script?.src ? script.src : `https://www.googletagmanager.com/gtm.js?id=${id}`,
|
|
75
|
+
category: script?.category ?? 'necessary',
|
|
76
|
+
async: script?.async ?? true,
|
|
77
|
+
alwaysLoad: true,
|
|
78
|
+
onBeforeLoad: ({ consents, elementId, ...rest })=>{
|
|
79
|
+
const gtmConsent = consents ? mapConsentStateToGTM(consents) : DEFAULT_GTM_CONSENT_CONFIG;
|
|
80
|
+
const setupScript = document.createElement("script");
|
|
81
|
+
setupScript.id = `${elementId}-init`;
|
|
82
|
+
setupScript.textContent = `
|
|
83
|
+
window.dataLayer = window.dataLayer || [];
|
|
84
|
+
window.gtag = function gtag() {
|
|
85
|
+
window.dataLayer.push(arguments);
|
|
86
|
+
};
|
|
87
|
+
window.gtag('consent', 'default', {
|
|
88
|
+
...${JSON.stringify(gtmConsent)},
|
|
89
|
+
});
|
|
90
|
+
window.dataLayer.push({
|
|
91
|
+
'gtm.start': Date.now(),
|
|
92
|
+
event: 'gtm.js',
|
|
93
|
+
});
|
|
94
|
+
`;
|
|
95
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
96
|
+
document.head.appendChild(setupScript);
|
|
97
|
+
if (script?.onBeforeLoad) script.onBeforeLoad({
|
|
98
|
+
consents,
|
|
99
|
+
elementId,
|
|
100
|
+
...rest
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
onDelete: ({ elementId, ...rest })=>{
|
|
104
|
+
const setupScript = document.getElementById(`${elementId}-init`);
|
|
105
|
+
if (setupScript) setupScript.remove();
|
|
106
|
+
if (script?.onDelete) script.onDelete({
|
|
107
|
+
elementId,
|
|
108
|
+
...rest
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
onConsentChange ({ consents, ...rest }) {
|
|
112
|
+
if (window.gtag) {
|
|
113
|
+
window.gtag('consent', 'update', mapConsentStateToGTM(consents));
|
|
114
|
+
window.gtag('event', updateEventName ?? 'consent-update');
|
|
115
|
+
}
|
|
116
|
+
if (script?.onConsentChange) script.onConsentChange({
|
|
117
|
+
consents,
|
|
118
|
+
...rest
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
exports.DEFAULT_GTM_CONSENT_CONFIG = __webpack_exports__.DEFAULT_GTM_CONSENT_CONFIG;
|
|
124
|
+
exports.googleTagManager = __webpack_exports__.googleTagManager;
|
|
125
|
+
exports.mapConsentStateToGTM = __webpack_exports__.mapConsentStateToGTM;
|
|
126
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
127
|
+
"DEFAULT_GTM_CONSENT_CONFIG",
|
|
128
|
+
"googleTagManager",
|
|
129
|
+
"mapConsentStateToGTM"
|
|
130
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
131
|
+
Object.defineProperty(exports, '__esModule', {
|
|
132
|
+
value: true
|
|
133
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ConsentState, Script } from 'c15t';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
dataLayer: unknown[];
|
|
5
|
+
gtag: (...args: unknown[]) => void;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface GTMConsentConfiguration {
|
|
9
|
+
ad_storage: 'granted' | 'denied';
|
|
10
|
+
ad_personalization: 'granted' | 'denied';
|
|
11
|
+
ad_user_data: 'granted' | 'denied';
|
|
12
|
+
analytics_storage: 'granted' | 'denied';
|
|
13
|
+
personalization_storage: 'granted' | 'denied';
|
|
14
|
+
functionality_storage: 'granted' | 'denied';
|
|
15
|
+
security_storage: 'granted' | 'denied';
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_GTM_CONSENT_CONFIG: GTMConsentConfiguration;
|
|
18
|
+
/**
|
|
19
|
+
* Converts ConsentState to GTM consent configuration
|
|
20
|
+
*
|
|
21
|
+
* @param consentState - The application's consent state
|
|
22
|
+
* @returns GTM-compatible consent configuration
|
|
23
|
+
*
|
|
24
|
+
* @see {@link CONSENT_STATE_TO_GTM_MAPPING} for the mapping logic
|
|
25
|
+
*/
|
|
26
|
+
export declare function mapConsentStateToGTM(consentState: ConsentState): GTMConsentConfiguration;
|
|
27
|
+
export interface GoogleTagManagerOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Your Google Tag Manager container ID. Begins with 'GTM-'.
|
|
30
|
+
* @example `GTM-1234XXX`
|
|
31
|
+
*/
|
|
32
|
+
id: string;
|
|
33
|
+
/**
|
|
34
|
+
* Update Event Name
|
|
35
|
+
* A custom event name used as a trigger to load your script once the consent has been updated.
|
|
36
|
+
*
|
|
37
|
+
* @default 'consent-update'
|
|
38
|
+
* @example 'consent-update'
|
|
39
|
+
*/
|
|
40
|
+
updateEventName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Override or extend the default script values.
|
|
43
|
+
*
|
|
44
|
+
* Default values:
|
|
45
|
+
* - `id`: 'google-tag-manager'
|
|
46
|
+
* - `src`: `https://www.googletagmanager.com/gtm.js?id=${id}`
|
|
47
|
+
* - `category`: 'necessary' (You control what scripts get loaded via Google Tag Manager)
|
|
48
|
+
* - `alwaysLoad`: true
|
|
49
|
+
* - `async`: true
|
|
50
|
+
*/
|
|
51
|
+
script?: Partial<Script>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Google Tag Manager script.
|
|
55
|
+
* GTM can be used for managing the consent of other scripts via Google Tag Manager consent mode.
|
|
56
|
+
* We recommend using c15t's script loader instead so your script logic is centralised.
|
|
57
|
+
*
|
|
58
|
+
* @param options - The options for the Google Tag Manager script.
|
|
59
|
+
* @returns The Google Tag Manager script.
|
|
60
|
+
*/
|
|
61
|
+
export declare function googleTagManager({ id, script, updateEventName, }: GoogleTagManagerOptions): Script;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=google-tag-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-tag-manager.d.ts","sourceRoot":"","sources":["../src/google-tag-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACnC;CACD;AAGD,UAAU,uBAAuB;IAChC,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,kBAAkB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACzC,YAAY,EAAE,SAAS,GAAG,QAAQ,CAAC;IACnC,iBAAiB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACxC,uBAAuB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC9C,qBAAqB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5C,gBAAgB,EAAE,SAAS,GAAG,QAAQ,CAAC;CACvC;AAGD,eAAO,MAAM,0BAA0B,EAAE,uBAQ/B,CAAC;AAaX;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,YAAY,EAAE,YAAY,GACxB,uBAAuB,CAczB;AAED,MAAM,WAAW,uBAAuB;IACvC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,EAChC,EAAE,EACF,MAAM,EACN,eAAe,GACf,EAAE,uBAAuB,GAAG,MAAM,CAwElC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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'
|
|
16
|
+
],
|
|
17
|
+
measurement: [
|
|
18
|
+
'analytics_storage'
|
|
19
|
+
],
|
|
20
|
+
marketing: [
|
|
21
|
+
'ad_storage',
|
|
22
|
+
'ad_user_data',
|
|
23
|
+
'ad_personalization'
|
|
24
|
+
],
|
|
25
|
+
experience: [
|
|
26
|
+
'personalization_storage'
|
|
27
|
+
]
|
|
28
|
+
};
|
|
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)},
|
|
59
|
+
});
|
|
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
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export { DEFAULT_GTM_CONSENT_CONFIG, googleTagManager, mapConsentStateToGTM };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
gtag: ()=>gtag
|
|
28
|
+
});
|
|
29
|
+
const external_google_tag_manager_cjs_namespaceObject = require("./google-tag-manager.cjs");
|
|
30
|
+
function gtag({ id, script, category }) {
|
|
31
|
+
return {
|
|
32
|
+
...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);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
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__];
|
|
73
|
+
Object.defineProperty(exports, '__esModule', {
|
|
74
|
+
value: true
|
|
75
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AllConsentNames, Script } from 'c15t';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
dataLayer: unknown[];
|
|
5
|
+
gtag: (...args: unknown[]) => void;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface GtagOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Your gtag id
|
|
11
|
+
* @example `G-XXXXXXX`
|
|
12
|
+
*/
|
|
13
|
+
id: string;
|
|
14
|
+
/**
|
|
15
|
+
* The consent category to use for the gtag script. This is typically marketing (Ads & Floodlight) or measurement (Analytics)
|
|
16
|
+
* @example 'marketing'
|
|
17
|
+
*/
|
|
18
|
+
category: AllConsentNames;
|
|
19
|
+
/**
|
|
20
|
+
* Override or extend the default script values.
|
|
21
|
+
*
|
|
22
|
+
* Default values:
|
|
23
|
+
* - `id`: 'gtag'
|
|
24
|
+
* - `src`: `https://www.googletagmanager.com/gtag/js?id=${id}`
|
|
25
|
+
* - `async`: true
|
|
26
|
+
* - `alwaysLoad`: true
|
|
27
|
+
*/
|
|
28
|
+
script?: Partial<Omit<Script, 'category'>>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a Google Tag (gtag.js) script.
|
|
32
|
+
* Allows you to send data website to linked Google products like Analytics, Ads & Floodlight.
|
|
33
|
+
*
|
|
34
|
+
* @param options - The options for the gtag script.
|
|
35
|
+
* @returns The Google Tag Manager script.
|
|
36
|
+
*/
|
|
37
|
+
export declare function gtag({ id, script, category }: GtagOptions): Script;
|
|
38
|
+
//# sourceMappingURL=google-tag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-tag.d.ts","sourceRoot":"","sources":["../src/google-tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAQpD,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACnC;CACD;AAED,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,QAAQ,EAAE,eAAe,CAAC;IAE1B;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW,GAAG,MAAM,CAsDlE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__ from "./google-tag-manager.js";
|
|
2
|
+
function gtag({ id, script, category }) {
|
|
3
|
+
return {
|
|
4
|
+
...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 = __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__.DEFAULT_GTM_CONSENT_CONFIG;
|
|
13
|
+
if (consents) gtmConsent = (0, __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__.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', (0, __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__.mapConsentStateToGTM)(args.consents));
|
|
37
|
+
if (script?.onConsentChange) script.onConsentChange(args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export { gtag };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
linkedinInsights: ()=>linkedinInsights
|
|
28
|
+
});
|
|
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
|
+
});
|
|
58
|
+
},
|
|
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
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
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__];
|
|
72
|
+
Object.defineProperty(exports, '__esModule', {
|
|
73
|
+
value: true
|
|
74
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Script } from 'c15t';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
lintrk: ((...args: unknown[]) => void) & {
|
|
5
|
+
q?: unknown[][];
|
|
6
|
+
};
|
|
7
|
+
_linkedin_partner_id?: string;
|
|
8
|
+
_linkedin_data_partner_ids?: string[];
|
|
9
|
+
ORIBILI?: {
|
|
10
|
+
_DEBUG?: {
|
|
11
|
+
disableScript?: () => void;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export interface LinkedInInsightsOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Your LinkedIn Insights ID
|
|
19
|
+
* @example `123456789012345`
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
/**
|
|
23
|
+
* Override or extend the default script values.
|
|
24
|
+
*
|
|
25
|
+
* Default values:
|
|
26
|
+
* - `id`: 'linkedin-insights'
|
|
27
|
+
* - `src`: `https://snap.licdn.com/li.lms-analytics/insight.min.js`
|
|
28
|
+
* - `category`: 'marketing'
|
|
29
|
+
*/
|
|
30
|
+
script?: Partial<Script>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* LinkedIn Insights Script
|
|
34
|
+
*
|
|
35
|
+
* @param options - The options for the LinkedIn Insights script
|
|
36
|
+
* @returns The LinkedIn Insights script configuration
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const linkedinInsightsScript = linkedinInsights({
|
|
41
|
+
* id: '123456789012345',
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://business.linkedin.com/marketing-solutions/ad-libraries/insights} LinkedIn Insights documentation
|
|
46
|
+
*/
|
|
47
|
+
export declare function linkedinInsights({ id, script, }: LinkedInInsightsOptions): Script;
|
|
48
|
+
//# sourceMappingURL=linkedin-insights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linkedin-insights.d.ts","sourceRoot":"","sources":["../src/linkedin-insights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,GAAG;YAAE,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CAAA;SAAE,CAAC;QAC7D,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC;QACtC,OAAO,CAAC,EAAE;YACT,MAAM,CAAC,EAAE;gBACR,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;aAC3B,CAAC;SACF,CAAC;KACF;CACD;AAED,MAAM,WAAW,uBAAuB;IACvC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,EAChC,EAAE,EACF,MAAM,GACN,EAAE,uBAAuB,GAAG,MAAM,CAmDlC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
});
|
|
30
|
+
},
|
|
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
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export { linkedinInsights };
|