@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,63 @@
|
|
|
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
|
+
metaPixel: ()=>metaPixel,
|
|
28
|
+
metaPixelEvent: ()=>metaPixelEvent
|
|
29
|
+
});
|
|
30
|
+
function metaPixel({ pixelId, script }) {
|
|
31
|
+
return {
|
|
32
|
+
id: script?.id ?? 'meta-pixel',
|
|
33
|
+
category: script?.category ?? 'marketing',
|
|
34
|
+
textContent: `
|
|
35
|
+
!function(f,b,e,v,n,t,s)
|
|
36
|
+
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
|
|
37
|
+
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
|
|
38
|
+
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
|
|
39
|
+
n.queue=[];t=b.createElement(e);t.async=!0;
|
|
40
|
+
t.src=v;s=b.getElementsByTagName(e)[0];
|
|
41
|
+
s.parentNode.insertBefore(t,s)}(window, document,'script',
|
|
42
|
+
'${script?.src ?? 'https://connect.facebook.net/en_US/fbevents.js'}');
|
|
43
|
+
fbq('consent', 'grant');
|
|
44
|
+
fbq('init', '${pixelId}');
|
|
45
|
+
fbq('track', 'PageView');
|
|
46
|
+
`.trim(),
|
|
47
|
+
persistAfterConsentRevoked: true,
|
|
48
|
+
onDelete: (payload)=>{
|
|
49
|
+
window.fbq('consent', 'revoke');
|
|
50
|
+
if (script?.onDelete) script.onDelete(payload);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const metaPixelEvent = (eventName, params, eventId)=>window.fbq('track', eventName, params, eventId);
|
|
55
|
+
exports.metaPixel = __webpack_exports__.metaPixel;
|
|
56
|
+
exports.metaPixelEvent = __webpack_exports__.metaPixelEvent;
|
|
57
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
58
|
+
"metaPixel",
|
|
59
|
+
"metaPixelEvent"
|
|
60
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
61
|
+
Object.defineProperty(exports, '__esModule', {
|
|
62
|
+
value: true
|
|
63
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { Script } from 'c15t';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the `contents` array object property.
|
|
4
|
+
*/
|
|
5
|
+
export interface FbqContent {
|
|
6
|
+
id: string | number;
|
|
7
|
+
quantity: number;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base interface for all possible event parameters.
|
|
12
|
+
* All properties are optional here; specific event types will make them required.
|
|
13
|
+
*/
|
|
14
|
+
export interface FbqBaseEventParams {
|
|
15
|
+
content_category?: string;
|
|
16
|
+
content_ids?: (string | number)[];
|
|
17
|
+
content_name?: string;
|
|
18
|
+
content_type?: 'product' | 'product_group';
|
|
19
|
+
contents?: FbqContent[];
|
|
20
|
+
currency?: string;
|
|
21
|
+
num_items?: number;
|
|
22
|
+
predicted_ltv?: number;
|
|
23
|
+
search_string?: string;
|
|
24
|
+
status?: boolean;
|
|
25
|
+
value?: number;
|
|
26
|
+
}
|
|
27
|
+
type AddPaymentInfoParams = Pick<FbqBaseEventParams, 'content_ids' | 'contents' | 'currency' | 'value'>;
|
|
28
|
+
type AddToCartParams = Pick<FbqBaseEventParams, 'content_ids' | 'content_type' | 'contents' | 'currency' | 'value'>;
|
|
29
|
+
type AddToWishlistParams = Pick<FbqBaseEventParams, 'content_ids' | 'contents' | 'currency' | 'value'>;
|
|
30
|
+
type CompleteRegistrationParams = Pick<FbqBaseEventParams, 'currency' | 'value' | 'status'>;
|
|
31
|
+
type InitiateCheckoutParams = Pick<FbqBaseEventParams, 'content_ids' | 'contents' | 'currency' | 'num_items' | 'value'>;
|
|
32
|
+
type LeadParams = Pick<FbqBaseEventParams, 'currency' | 'value'>;
|
|
33
|
+
type SearchParams = Pick<FbqBaseEventParams, 'content_ids' | 'content_type' | 'contents' | 'currency' | 'search_string' | 'value'>;
|
|
34
|
+
type StartTrialParams = Pick<FbqBaseEventParams, 'currency' | 'predicted_ltv' | 'value'>;
|
|
35
|
+
type SubscribeParams = Pick<FbqBaseEventParams, 'currency' | 'predicted_ltv' | 'value'>;
|
|
36
|
+
type ViewContentParams = Pick<FbqBaseEventParams, 'content_ids' | 'content_type' | 'contents' | 'currency' | 'value'>;
|
|
37
|
+
/**
|
|
38
|
+
* The 'Purchase' event has required properties.
|
|
39
|
+
* We use TypeScript's utility types to enforce this.
|
|
40
|
+
*/
|
|
41
|
+
type PurchaseParams = Pick<FbqBaseEventParams, 'content_ids' | 'content_type' | 'contents' | 'num_items'> & Required<Pick<FbqBaseEventParams, 'currency' | 'value'>>;
|
|
42
|
+
/**
|
|
43
|
+
* Events with no specific properties listed can accept any of the base parameters.
|
|
44
|
+
*/
|
|
45
|
+
type ContactParams = FbqBaseEventParams;
|
|
46
|
+
type CustomizeProductParams = FbqBaseEventParams;
|
|
47
|
+
type DonateParams = FbqBaseEventParams;
|
|
48
|
+
type FindLocationParams = FbqBaseEventParams;
|
|
49
|
+
type ScheduleParams = FbqBaseEventParams;
|
|
50
|
+
type SubmitApplicationParams = FbqBaseEventParams;
|
|
51
|
+
/**
|
|
52
|
+
* A mapping of Standard Event names to their corresponding parameter types.
|
|
53
|
+
* This is the core of our type-safety mechanism.
|
|
54
|
+
*/
|
|
55
|
+
export interface StandardEventParams {
|
|
56
|
+
AddPaymentInfo: AddPaymentInfoParams;
|
|
57
|
+
AddToCart: AddToCartParams;
|
|
58
|
+
AddToWishlist: AddToWishlistParams;
|
|
59
|
+
CompleteRegistration: CompleteRegistrationParams;
|
|
60
|
+
Contact: ContactParams;
|
|
61
|
+
CustomizeProduct: CustomizeProductParams;
|
|
62
|
+
Donate: DonateParams;
|
|
63
|
+
FindLocation: FindLocationParams;
|
|
64
|
+
InitiateCheckout: InitiateCheckoutParams;
|
|
65
|
+
Lead: LeadParams;
|
|
66
|
+
Purchase: PurchaseParams;
|
|
67
|
+
Schedule: ScheduleParams;
|
|
68
|
+
Search: SearchParams;
|
|
69
|
+
StartTrial: StartTrialParams;
|
|
70
|
+
SubmitApplication: SubmitApplicationParams;
|
|
71
|
+
Subscribe: SubscribeParams;
|
|
72
|
+
ViewContent: ViewContentParams;
|
|
73
|
+
}
|
|
74
|
+
export type StandardEventName = keyof StandardEventParams;
|
|
75
|
+
declare global {
|
|
76
|
+
interface Window {
|
|
77
|
+
fbq: {
|
|
78
|
+
(command: 'init', pixelId: string): void;
|
|
79
|
+
(command: 'track', eventName: StandardEventName, params?: StandardEventParams[StandardEventName], eventId?: string): void;
|
|
80
|
+
(command: 'consent', action: 'grant' | 'revoke'): void;
|
|
81
|
+
(...args: unknown[]): void;
|
|
82
|
+
};
|
|
83
|
+
_fbq: Window['fbq'];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export interface MetaPixelOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Your Meta Pixel ID
|
|
89
|
+
* @example `123456789012345`
|
|
90
|
+
*/
|
|
91
|
+
pixelId: string;
|
|
92
|
+
/**
|
|
93
|
+
* Override or extend the default script values.
|
|
94
|
+
*
|
|
95
|
+
* Default values:
|
|
96
|
+
* - `id`: 'meta-pixel'
|
|
97
|
+
* - `src`: `https://connect.facebook.net/en_US/fbevents.js`
|
|
98
|
+
* - `category`: 'marketing'
|
|
99
|
+
*/
|
|
100
|
+
script?: Partial<Script>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a Meta Pixel script with inline JavaScript code.
|
|
104
|
+
*
|
|
105
|
+
* This script uses textContent to inject the Meta Pixel tracking code directly
|
|
106
|
+
* into the page, which is the recommended approach for Meta Pixel implementation.
|
|
107
|
+
*
|
|
108
|
+
* @param options - The options for the Meta Pixel script
|
|
109
|
+
* @returns The Meta Pixel script configuration
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const metaPixelScript = metaPixel({
|
|
114
|
+
* pixelId: '123456789012345',
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @see {@link https://developers.facebook.com/docs/meta-pixel/get-started} Meta Pixel documentation
|
|
119
|
+
*/
|
|
120
|
+
export declare function metaPixel({ pixelId, script }: MetaPixelOptions): Script;
|
|
121
|
+
/**
|
|
122
|
+
* Meta Pixel Event
|
|
123
|
+
* This is a wrapper around the `fbq` function that the Meta Pixel script uses.
|
|
124
|
+
*
|
|
125
|
+
* @param eventName - The event name to track
|
|
126
|
+
* @param params - Optional parameters to track
|
|
127
|
+
* @param eventId - Optional event ID to track (If using Conversion API)
|
|
128
|
+
*
|
|
129
|
+
* @usage
|
|
130
|
+
* ```ts
|
|
131
|
+
* metaPixelEvent('Purchase', { value: 10.0, currency: 'USD' });
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @see {@link https://developers.facebook.com/docs/meta-pixel/reference} Meta Pixel documentation
|
|
135
|
+
*/
|
|
136
|
+
export declare const metaPixelEvent: <TEventName extends StandardEventName>(eventName: TEventName, params?: StandardEventParams[TEventName], eventId?: string) => void;
|
|
137
|
+
export {};
|
|
138
|
+
//#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BAAgB,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,gBAAgB,GAAG,MAAM,CA6BvE;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,iBAAiB,EAClE,WAAW,UAAU,EACrB,SAAS,mBAAmB,CAAC,UAAU,CAAC,EACxC,UAAU,MAAM,SACmC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function metaPixel({ pixelId, script }) {
|
|
2
|
+
return {
|
|
3
|
+
id: script?.id ?? 'meta-pixel',
|
|
4
|
+
category: script?.category ?? 'marketing',
|
|
5
|
+
textContent: `
|
|
6
|
+
!function(f,b,e,v,n,t,s)
|
|
7
|
+
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
|
|
8
|
+
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
|
|
9
|
+
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
|
|
10
|
+
n.queue=[];t=b.createElement(e);t.async=!0;
|
|
11
|
+
t.src=v;s=b.getElementsByTagName(e)[0];
|
|
12
|
+
s.parentNode.insertBefore(t,s)}(window, document,'script',
|
|
13
|
+
'${script?.src ?? 'https://connect.facebook.net/en_US/fbevents.js'}');
|
|
14
|
+
fbq('consent', 'grant');
|
|
15
|
+
fbq('init', '${pixelId}');
|
|
16
|
+
fbq('track', 'PageView');
|
|
17
|
+
`.trim(),
|
|
18
|
+
persistAfterConsentRevoked: true,
|
|
19
|
+
onDelete: (payload)=>{
|
|
20
|
+
window.fbq('consent', 'revoke');
|
|
21
|
+
if (script?.onDelete) script.onDelete(payload);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const metaPixelEvent = (eventName, params, eventId)=>window.fbq('track', eventName, params, eventId);
|
|
26
|
+
export { metaPixel, metaPixelEvent };
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
microsoftUet: ()=>microsoftUet
|
|
28
|
+
});
|
|
29
|
+
function microsoftUet({ id, script }) {
|
|
30
|
+
const category = script?.category ?? 'marketing';
|
|
31
|
+
return {
|
|
32
|
+
id: script?.id ?? 'microsoft-uet',
|
|
33
|
+
category,
|
|
34
|
+
textContent: `
|
|
35
|
+
(function(w,d,t,r,u)
|
|
36
|
+
{
|
|
37
|
+
var f,n,i;
|
|
38
|
+
w[u]=w[u]||[],f=function()
|
|
39
|
+
{
|
|
40
|
+
var o={ti:"${id}", enableAutoSpaTracking: true};
|
|
41
|
+
o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")
|
|
42
|
+
},
|
|
43
|
+
n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function()
|
|
44
|
+
{
|
|
45
|
+
var s=this.readyState;
|
|
46
|
+
s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)
|
|
47
|
+
},
|
|
48
|
+
i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)
|
|
49
|
+
})
|
|
50
|
+
(window,document,"script","${script?.src ?? '//bat.bing.com/bat.js'}","uetq");
|
|
51
|
+
`.trim(),
|
|
52
|
+
onLoad: (rest)=>{
|
|
53
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
54
|
+
const existingElement = document.getElementById(`${rest.elementId}-default`);
|
|
55
|
+
if (existingElement) {
|
|
56
|
+
window.uetq = window.uetq || [];
|
|
57
|
+
window.uetq.push('consent', 'update', {
|
|
58
|
+
ad_storage: 'granted'
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
const defaultConsentScript = document.createElement("script");
|
|
62
|
+
defaultConsentScript.id = `${rest.elementId}-default`;
|
|
63
|
+
defaultConsentScript.textContent = `
|
|
64
|
+
window.uetq = window.uetq || [];
|
|
65
|
+
window.uetq.push('consent', 'default', {
|
|
66
|
+
ad_storage: 'granted',
|
|
67
|
+
});
|
|
68
|
+
`;
|
|
69
|
+
document.head.appendChild(defaultConsentScript);
|
|
70
|
+
}
|
|
71
|
+
if (script?.onLoad) script.onLoad(rest);
|
|
72
|
+
},
|
|
73
|
+
onDelete ({ elementId, ...rest }) {
|
|
74
|
+
window.uetq?.push('consent', 'update', {
|
|
75
|
+
ad_storage: 'denied'
|
|
76
|
+
});
|
|
77
|
+
if (script?.onDelete) script.onDelete({
|
|
78
|
+
elementId,
|
|
79
|
+
...rest
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.microsoftUet = __webpack_exports__.microsoftUet;
|
|
85
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
86
|
+
"microsoftUet"
|
|
87
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
88
|
+
Object.defineProperty(exports, '__esModule', {
|
|
89
|
+
value: true
|
|
90
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Script } from 'c15t';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
uetq: unknown[] | undefined;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface MicrosoftUetOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Your Microsoft UET ID
|
|
10
|
+
* @example `123456789012345`
|
|
11
|
+
*/
|
|
12
|
+
id: string;
|
|
13
|
+
/**
|
|
14
|
+
* Override or extend the default script values.
|
|
15
|
+
*
|
|
16
|
+
* Default values:
|
|
17
|
+
* - `id`: 'microsoft-uet'
|
|
18
|
+
* - `src`: `//bat.bing.com/bat.js`
|
|
19
|
+
* - `category`: 'marketing'
|
|
20
|
+
*/
|
|
21
|
+
script?: Partial<Script>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Microsoft UET Script
|
|
25
|
+
* This script is persistent after consent is revoked because it has built-in functionality to opt into and out of tracking based on consent, which allows us to not need to load the script again when consent is revoked.
|
|
26
|
+
*
|
|
27
|
+
* @param options - The options for the Microsoft UET script
|
|
28
|
+
* @returns The Microsoft UET script configuration
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const microsoftUetScript = microsoftUet({
|
|
33
|
+
* id: '123456789012345',
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see https://learn.microsoft.com/en-us/advertising/guides/universal-event-tracking?view=bingads-13
|
|
38
|
+
*/
|
|
39
|
+
export declare function microsoftUet({ id, script }: MicrosoftUetOptions): Script;
|
|
40
|
+
//# sourceMappingURL=microsoft-uet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microsoft-uet.d.ts","sourceRoot":"","sources":["../src/microsoft-uet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;KAC5B;CACD;AAED,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,mBAAmB,GAAG,MAAM,CAkExE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function microsoftUet({ id, script }) {
|
|
2
|
+
const category = script?.category ?? 'marketing';
|
|
3
|
+
return {
|
|
4
|
+
id: script?.id ?? 'microsoft-uet',
|
|
5
|
+
category,
|
|
6
|
+
textContent: `
|
|
7
|
+
(function(w,d,t,r,u)
|
|
8
|
+
{
|
|
9
|
+
var f,n,i;
|
|
10
|
+
w[u]=w[u]||[],f=function()
|
|
11
|
+
{
|
|
12
|
+
var o={ti:"${id}", enableAutoSpaTracking: true};
|
|
13
|
+
o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")
|
|
14
|
+
},
|
|
15
|
+
n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function()
|
|
16
|
+
{
|
|
17
|
+
var s=this.readyState;
|
|
18
|
+
s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)
|
|
19
|
+
},
|
|
20
|
+
i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)
|
|
21
|
+
})
|
|
22
|
+
(window,document,"script","${script?.src ?? '//bat.bing.com/bat.js'}","uetq");
|
|
23
|
+
`.trim(),
|
|
24
|
+
onLoad: (rest)=>{
|
|
25
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
26
|
+
const existingElement = document.getElementById(`${rest.elementId}-default`);
|
|
27
|
+
if (existingElement) {
|
|
28
|
+
window.uetq = window.uetq || [];
|
|
29
|
+
window.uetq.push('consent', 'update', {
|
|
30
|
+
ad_storage: 'granted'
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
const defaultConsentScript = document.createElement("script");
|
|
34
|
+
defaultConsentScript.id = `${rest.elementId}-default`;
|
|
35
|
+
defaultConsentScript.textContent = `
|
|
36
|
+
window.uetq = window.uetq || [];
|
|
37
|
+
window.uetq.push('consent', 'default', {
|
|
38
|
+
ad_storage: 'granted',
|
|
39
|
+
});
|
|
40
|
+
`;
|
|
41
|
+
document.head.appendChild(defaultConsentScript);
|
|
42
|
+
}
|
|
43
|
+
if (script?.onLoad) script.onLoad(rest);
|
|
44
|
+
},
|
|
45
|
+
onDelete ({ elementId, ...rest }) {
|
|
46
|
+
window.uetq?.push('consent', 'update', {
|
|
47
|
+
ad_storage: 'denied'
|
|
48
|
+
});
|
|
49
|
+
if (script?.onDelete) script.onDelete({
|
|
50
|
+
elementId,
|
|
51
|
+
...rest
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { microsoftUet };
|
package/dist/posthog.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
posthog: ()=>posthog
|
|
28
|
+
});
|
|
29
|
+
function posthog(options) {
|
|
30
|
+
const { script } = options;
|
|
31
|
+
const handleConsentOpt = (hasConsent)=>{
|
|
32
|
+
const posthogConsent = window.posthog.get_explicit_consent_status();
|
|
33
|
+
if (hasConsent && 'granted' !== posthogConsent) window.posthog.opt_in_capturing();
|
|
34
|
+
else if (!hasConsent && 'denied' !== posthogConsent) window.posthog.opt_out_capturing();
|
|
35
|
+
};
|
|
36
|
+
const apiHost = options.apiHost.replace('.i.posthog.com', '-assets.i.posthog.com');
|
|
37
|
+
const scriptUrl = `${apiHost}/static/array.js`;
|
|
38
|
+
return {
|
|
39
|
+
id: script?.id ?? 'posthog',
|
|
40
|
+
category: script?.category ?? 'measurement',
|
|
41
|
+
src: scriptUrl,
|
|
42
|
+
async: true,
|
|
43
|
+
attributes: {
|
|
44
|
+
crossorigin: 'anonymous',
|
|
45
|
+
'data-api-host': options.apiHost,
|
|
46
|
+
'data-ui-host': options.apiHost
|
|
47
|
+
},
|
|
48
|
+
alwaysLoad: true,
|
|
49
|
+
onBeforeLoad: (rest)=>{
|
|
50
|
+
if (!window.posthog) window.posthog = {
|
|
51
|
+
init: ()=>{},
|
|
52
|
+
opt_in_capturing: ()=>{},
|
|
53
|
+
opt_out_capturing: ()=>{},
|
|
54
|
+
get_explicit_consent_status: ()=>'pending'
|
|
55
|
+
};
|
|
56
|
+
script?.onBeforeLoad?.(rest);
|
|
57
|
+
},
|
|
58
|
+
onLoad: ({ hasConsent, ...rest })=>{
|
|
59
|
+
if (window.posthog && 'function' == typeof window.posthog.init) {
|
|
60
|
+
window.posthog.init(options.id, {
|
|
61
|
+
api_host: options.apiHost,
|
|
62
|
+
ui_host: options.apiHost,
|
|
63
|
+
autocapture: false,
|
|
64
|
+
...options.options || {}
|
|
65
|
+
});
|
|
66
|
+
handleConsentOpt(hasConsent);
|
|
67
|
+
}
|
|
68
|
+
script?.onLoad?.({
|
|
69
|
+
hasConsent,
|
|
70
|
+
...rest
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
onConsentChange: ({ hasConsent, ...rest })=>{
|
|
74
|
+
handleConsentOpt(hasConsent);
|
|
75
|
+
script?.onConsentChange?.({
|
|
76
|
+
hasConsent,
|
|
77
|
+
...rest
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
exports.posthog = __webpack_exports__.posthog;
|
|
83
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
84
|
+
"posthog"
|
|
85
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
86
|
+
Object.defineProperty(exports, '__esModule', {
|
|
87
|
+
value: true
|
|
88
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Script } from 'c15t';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
posthog: {
|
|
5
|
+
init: (token: string, options: {
|
|
6
|
+
api_host: string;
|
|
7
|
+
ui_host?: string;
|
|
8
|
+
autocapture?: boolean;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}) => void;
|
|
11
|
+
opt_in_capturing: () => void;
|
|
12
|
+
opt_out_capturing: () => void;
|
|
13
|
+
get_explicit_consent_status: () => string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export interface PosthogConsentOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Your posthog id, begins with 'phc_'.
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
/**
|
|
23
|
+
* Your posthog api host.
|
|
24
|
+
* @default 'https://eu.i.posthog.com'
|
|
25
|
+
*/
|
|
26
|
+
apiHost: string;
|
|
27
|
+
/**
|
|
28
|
+
* The defaults for the posthog script.
|
|
29
|
+
*/
|
|
30
|
+
defaults: string;
|
|
31
|
+
/**
|
|
32
|
+
* Other optional options for the posthog script.
|
|
33
|
+
* @example { person_profiles: 'identified_only' }
|
|
34
|
+
*/
|
|
35
|
+
options: Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Override or extend the default script values.
|
|
38
|
+
*
|
|
39
|
+
* Default values:
|
|
40
|
+
* - `id`: 'posthog-consent'
|
|
41
|
+
* - `category`: 'measurement'
|
|
42
|
+
*/
|
|
43
|
+
script?: Partial<Script>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Loads the PostHog script and initializes it with the given options.
|
|
47
|
+
* This uses posthog.opt_in_capturing() to opt in to capturing. And posthog.opt_out_capturing() to opt out of capturing.
|
|
48
|
+
* @see https://posthog.com/docs/libraries/js#opt-in-capturing
|
|
49
|
+
*
|
|
50
|
+
* @param options - Optional configuration for the PostHog consent script
|
|
51
|
+
* @returns The Posthog script
|
|
52
|
+
*/
|
|
53
|
+
export declare function posthog(options: PosthogConsentOptions): Script;
|
|
54
|
+
//# sourceMappingURL=posthog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog.d.ts","sourceRoot":"","sources":["../src/posthog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,OAAO,EAAE;YACR,IAAI,EAAE,CACL,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;gBACR,QAAQ,EAAE,MAAM,CAAC;gBACjB,OAAO,CAAC,EAAE,MAAM,CAAC;gBACjB,WAAW,CAAC,EAAE,OAAO,CAAC;gBACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;aACvB,KACG,IAAI,CAAC;YACV,gBAAgB,EAAE,MAAM,IAAI,CAAC;YAC7B,iBAAiB,EAAE,MAAM,IAAI,CAAC;YAC9B,2BAA2B,EAAE,MAAM,MAAM,CAAC;SAC1C,CAAC;KACF;CACD;AAED,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAkE9D"}
|
package/dist/posthog.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function posthog(options) {
|
|
2
|
+
const { script } = options;
|
|
3
|
+
const handleConsentOpt = (hasConsent)=>{
|
|
4
|
+
const posthogConsent = window.posthog.get_explicit_consent_status();
|
|
5
|
+
if (hasConsent && 'granted' !== posthogConsent) window.posthog.opt_in_capturing();
|
|
6
|
+
else if (!hasConsent && 'denied' !== posthogConsent) window.posthog.opt_out_capturing();
|
|
7
|
+
};
|
|
8
|
+
const apiHost = options.apiHost.replace('.i.posthog.com', '-assets.i.posthog.com');
|
|
9
|
+
const scriptUrl = `${apiHost}/static/array.js`;
|
|
10
|
+
return {
|
|
11
|
+
id: script?.id ?? 'posthog',
|
|
12
|
+
category: script?.category ?? 'measurement',
|
|
13
|
+
src: scriptUrl,
|
|
14
|
+
async: true,
|
|
15
|
+
attributes: {
|
|
16
|
+
crossorigin: 'anonymous',
|
|
17
|
+
'data-api-host': options.apiHost,
|
|
18
|
+
'data-ui-host': options.apiHost
|
|
19
|
+
},
|
|
20
|
+
alwaysLoad: true,
|
|
21
|
+
onBeforeLoad: (rest)=>{
|
|
22
|
+
if (!window.posthog) window.posthog = {
|
|
23
|
+
init: ()=>{},
|
|
24
|
+
opt_in_capturing: ()=>{},
|
|
25
|
+
opt_out_capturing: ()=>{},
|
|
26
|
+
get_explicit_consent_status: ()=>'pending'
|
|
27
|
+
};
|
|
28
|
+
script?.onBeforeLoad?.(rest);
|
|
29
|
+
},
|
|
30
|
+
onLoad: ({ hasConsent, ...rest })=>{
|
|
31
|
+
if (window.posthog && 'function' == typeof window.posthog.init) {
|
|
32
|
+
window.posthog.init(options.id, {
|
|
33
|
+
api_host: options.apiHost,
|
|
34
|
+
ui_host: options.apiHost,
|
|
35
|
+
autocapture: false,
|
|
36
|
+
...options.options || {}
|
|
37
|
+
});
|
|
38
|
+
handleConsentOpt(hasConsent);
|
|
39
|
+
}
|
|
40
|
+
script?.onLoad?.({
|
|
41
|
+
hasConsent,
|
|
42
|
+
...rest
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
onConsentChange: ({ hasConsent, ...rest })=>{
|
|
46
|
+
handleConsentOpt(hasConsent);
|
|
47
|
+
script?.onConsentChange?.({
|
|
48
|
+
hasConsent,
|
|
49
|
+
...rest
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { posthog };
|