@c15t/scripts 1.0.0 → 1.0.1-canary-20251112105612

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/README.md CHANGED
@@ -1,39 +1,50 @@
1
1
  <p align="center">
2
- <a href="https://c15t.com?utm_source=github&utm_medium=repopage_%40c15t%2Ftranslations" target="_blank" rel="noopener noreferrer">
2
+ <a href="https://c15t.com?utm_source=github&utm_medium=repopage_%40c15t%2Fscripts" target="_blank" rel="noopener noreferrer">
3
3
  <picture>
4
4
  <source media="(prefers-color-scheme: dark)" srcset="../../docs/assets/c15t-banner-readme-dark.svg" type="image/svg+xml">
5
5
  <img src="../../docs/assets/c15t-banner-readme-light.svg" alt="c15t Banner" type="image/svg+xml">
6
6
  </picture>
7
7
  </a>
8
8
  <br />
9
- <h1 align="center">@c15t/scripts: Consent Management Scripts</h1>
9
+ <h1 align="center">@c15t/scripts: Prebuilt Consent Scripts</h1>
10
10
  </p>
11
11
 
12
12
  [![GitHub stars](https://img.shields.io/github/stars/c15t/c15t?style=flat-square)](https://github.com/c15t/c15t)
13
13
  [![CI](https://img.shields.io/github/actions/workflow/status/c15t/c15t/ci.yml?style=flat-square)](https://github.com/c15t/c15t/actions/workflows/ci.yml)
14
14
  [![License](https://img.shields.io/badge/license-GPL--3.0-blue.svg?style=flat-square)](https://github.com/c15t/c15t/blob/main/LICENSE.md)
15
- [![Discord](https://img.shields.io/discord/1312171102268690493?style=flat-square)](https://c15t.com/discord)
16
- [![npm version](https://img.shields.io/npm/v/%40c15t%2Ftranslations?style=flat-square)](https://www.npmjs.com/package/@c15t/translations)
15
+ [![Discord](https://img.shields.io/discord/1312171102268690493?style=flat-square)](https://c15t.link/discord)
16
+ [![npm version](https://img.shields.io/npm/v/%40c15t%2Fscripts?style=flat-square)](https://www.npmjs.com/package/@c15t/scripts)
17
17
  [![Top Language](https://img.shields.io/github/languages/top/c15t/c15t?style=flat-square)](https://github.com/c15t/c15t)
18
18
  [![Last Commit](https://img.shields.io/github/last-commit/c15t/c15t?style=flat-square)](https://github.com/c15t/c15t/commits/main)
19
19
  [![Open Issues](https://img.shields.io/github/issues/c15t/c15t?style=flat-square)](https://github.com/c15t/c15t/issues)
20
20
 
21
- Prebuilt scripts for c15t's script loader, for popular tools you may need to implement such as Google Tag Manager, Meta Pixel and more.
21
+ Prebuilt script integrations for c15t, providing ready-to-use consent-aware analytics and marketing scripts.
22
+
23
+ ## Key Features
24
+
25
+ - Prebuilt script snippets for popular analytics and marketing tools
26
+ - Easy integration with c15t's script loader
27
+ - Configuration options for each supported vendor
28
+ - Supported vendors include Google Tag Manager, Meta Pixel, PostHog, TikTok Pixel, LinkedIn Insights, Microsoft UET, and X Pixel
29
+
30
+ ## Documentation
31
+
32
+ For further information, guides, and examples visit the [reference documentation](https://c15t.com/docs/integrations).
22
33
 
23
34
  ## Scripts
24
35
 
25
- - [Google Tag Manager](https://c15t.com/docs/integrations/google-tag-manager)
26
- - [Google Tag](https://c15t.com/docs/integrations/google-tag)
27
- - [PostHog](https://c15t.com/docs/integrations/posthog)
28
- - [Meta Pixel](https://c15t.com/docs/integrations/meta-pixel)
29
- - [TikTok Pixel](https://c15t.com/docs/integrations/tiktok-pixel)
30
- - [LinkedIn Insights](https://c15t.com/docs/integrations/linkedin-insights)
31
- - [Microsoft UET](https://c15t.com/docs/integrations/microsoft-uet)
32
- - [X Pixel](https://c15t.com/docs/integrations/x-pixel)
36
+ - [Google Tag Manager](https://c15t.link/google-tag-manager)
37
+ - [Google Tag](https://c15t.link/google-tag)
38
+ - [PostHog](https://c15t.link/posthog)
39
+ - [Meta Pixel](https://c15t.link/meta-pixel)
40
+ - [TikTok Pixel](https://c15t.link/tiktok-pixel)
41
+ - [LinkedIn Insights](https://c15t.link/linkedin-insights)
42
+ - [Microsoft UET](https://c15t.link/microsoft-uet)
43
+ - [X Pixel](https://c15t.link/x-pixel)
33
44
 
34
45
  ## Support
35
46
 
36
- - Join our [Discord community](https://c15t.com/discord)
47
+ - Join our [Discord community](https://c15t.link/discord)
37
48
  - Open an issue on our [GitHub repository](https://github.com/c15t/c15t/issues)
38
49
  - Visit [consent.io](https://consent.io) and use the chat widget
39
50
  - Contact our support team via email [support@consent.io](mailto:support@consent.io)
@@ -67,4 +78,4 @@ Our preference is that you make use of GitHub's private vulnerability reporting
67
78
 
68
79
  ---
69
80
 
70
- **Built with ❤️ by the [consent.io](https://www.consent.io?utm_source=github&utm_medium=repopage_%40c15t%2Ftranslations) team**
81
+ **Built with ❤️ by the [consent.io](https://www.consent.io?utm_source=github&utm_medium=repopage_%40c15t%2Fscripts) team**
@@ -0,0 +1,85 @@
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
+ databuddy: ()=>databuddy
28
+ });
29
+ function databuddy(options) {
30
+ const { script } = options;
31
+ const handleConsentOpt = (hasConsent)=>{
32
+ if (!window.databuddy) return;
33
+ if (hasConsent && window.databuddy.options.disabled) window.databuddy.options.disabled = false;
34
+ else if (!hasConsent && !window.databuddy.options.disabled) window.databuddy.options.disabled = true;
35
+ };
36
+ return {
37
+ id: script?.id ?? 'databuddy',
38
+ category: script?.category ?? 'measurement',
39
+ src: options.scriptUrl ?? 'https://cdn.databuddy.cc/databuddy.js',
40
+ async: true,
41
+ attributes: {
42
+ crossorigin: 'anonymous',
43
+ 'data-client-id': options.clientId,
44
+ ...options.apiUrl ? {
45
+ 'data-api-url': options.apiUrl
46
+ } : {}
47
+ },
48
+ alwaysLoad: true,
49
+ onBeforeLoad: ({ hasConsent, ...rest })=>{
50
+ if (!window.databuddyConfig) window.databuddyConfig = {
51
+ clientId: options.clientId,
52
+ ...options.apiUrl ? {
53
+ apiUrl: options.apiUrl
54
+ } : {},
55
+ ...options.options || {},
56
+ disabled: !hasConsent
57
+ };
58
+ script?.onBeforeLoad?.({
59
+ hasConsent,
60
+ ...rest
61
+ });
62
+ },
63
+ onLoad: ({ hasConsent, ...rest })=>{
64
+ if (window.databuddy) handleConsentOpt(hasConsent);
65
+ script?.onLoad?.({
66
+ hasConsent,
67
+ ...rest
68
+ });
69
+ },
70
+ onConsentChange: ({ hasConsent, ...rest })=>{
71
+ handleConsentOpt(hasConsent);
72
+ script?.onConsentChange?.({
73
+ hasConsent,
74
+ ...rest
75
+ });
76
+ }
77
+ };
78
+ }
79
+ exports.databuddy = __webpack_exports__.databuddy;
80
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
81
+ "databuddy"
82
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
83
+ Object.defineProperty(exports, '__esModule', {
84
+ value: true
85
+ });
@@ -0,0 +1,104 @@
1
+ import type { Script } from 'c15t';
2
+ declare global {
3
+ interface Window {
4
+ databuddy?: {
5
+ track: (eventName: string, properties?: Record<string, unknown>) => void;
6
+ screenView: (screenName?: string, properties?: Record<string, unknown>) => void;
7
+ clear: () => void;
8
+ flush: () => void;
9
+ setGlobalProperties: (properties: Record<string, unknown>) => void;
10
+ trackCustomEvent: (eventName: string, properties?: Record<string, unknown>) => void;
11
+ options: {
12
+ disabled: boolean;
13
+ [key: string]: unknown;
14
+ };
15
+ };
16
+ databuddyConfig?: {
17
+ clientId?: string;
18
+ apiUrl?: string;
19
+ [key: string]: unknown;
20
+ };
21
+ }
22
+ }
23
+ export interface DatabuddyConsentOptions {
24
+ /**
25
+ * Your Databuddy client ID.
26
+ */
27
+ clientId: string;
28
+ /**
29
+ * Your Databuddy API URL.
30
+ * @default 'https://basket.databuddy.cc'
31
+ */
32
+ apiUrl?: string;
33
+ /**
34
+ * The Databuddy script URL.
35
+ * @default 'https://cdn.databuddy.cc/databuddy.js'
36
+ */
37
+ scriptUrl?: string;
38
+ /**
39
+ * Additional configuration options for Databuddy.
40
+ * @example { trackScreenViews: true, trackOutgoingLinks: true }
41
+ */
42
+ options?: Record<string, unknown>;
43
+ /**
44
+ * Override or extend the default script values.
45
+ *
46
+ * Default values:
47
+ * - `id`: 'databuddy'
48
+ * - `category`: 'measurement'
49
+ */
50
+ script?: Partial<Script>;
51
+ }
52
+ /**
53
+ * Loads the Databuddy script and manages consent state through a comprehensive lifecycle.
54
+ *
55
+ * This function orchestrates consent-aware analytics by coordinating between c15t's consent
56
+ * state and Databuddy's tracking behavior. The consent management lifecycle works as follows:
57
+ *
58
+ * 1. **Before Script Load** (`onBeforeLoad`): Seeds `window.databuddyConfig` with the client
59
+ * configuration, including setting `disabled: !hasConsent` to ensure Databuddy initializes
60
+ * in the correct state. The Databuddy script reads this configuration object on initialization.
61
+ *
62
+ * 2. **On Script Load** (`onLoad`): After Databuddy has initialized, verifies that
63
+ * `window.databuddy.options.disabled` matches the current consent state by calling
64
+ * `handleConsentOpt()`.
65
+ *
66
+ * 3. **On Consent Change** (`onConsentChange`): Dynamically toggles `window.databuddy.options.disabled`
67
+ * to enable tracking when consent is granted or disable tracking when consent is revoked.
68
+ * This ensures real-time compliance with user preferences.
69
+ *
70
+ * The script always loads (`alwaysLoad: true`) but tracking is controlled via the `disabled` flag,
71
+ * allowing Databuddy to remain present in the DOM while respecting consent boundaries.
72
+ *
73
+ * @param options - Configuration for the Databuddy consent script
74
+ * @returns The Databuddy script configuration object for c15t's script loader
75
+ *
76
+ * @throws This function does not throw errors directly. However, network failures or script
77
+ * loading errors may cause the Databuddy script to fail silently without initializing
78
+ * `window.databuddy`. The lifecycle callbacks handle these cases gracefully by checking for
79
+ * the presence of `window.databuddy` before attempting to modify its state.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * import { configureConsentManager } from 'c15t';
84
+ * import { databuddy } from '@c15t/scripts/databuddy';
85
+ *
86
+ * configureConsentManager({
87
+ * scripts: [
88
+ * databuddy({
89
+ * clientId: 'db_1234567890abcdef',
90
+ * // scriptUrl: 'https://cdn.databuddy.cc/databuddy.js', // Optional, defaults to cdn.databuddy.cc
91
+ * // apiUrl: 'https://basket.databuddy.cc', // Optional, defaults to basket.databuddy.cc
92
+ * options: {
93
+ * trackScreenViews: true,
94
+ * trackOutgoingLinks: true,
95
+ * trackPerformance: true,
96
+ * samplingRate: 1.0,
97
+ * },
98
+ * }),
99
+ * ],
100
+ * });
101
+ * ```
102
+ */
103
+ export declare function databuddy(options: DatabuddyConsentOptions): Script;
104
+ //# sourceMappingURL=databuddy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"databuddy.d.ts","sourceRoot":"","sources":["../src/databuddy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,CAAC,EAAE;YACX,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;YACzE,UAAU,EAAE,CACX,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAChC,IAAI,CAAC;YACV,KAAK,EAAE,MAAM,IAAI,CAAC;YAClB,KAAK,EAAE,MAAM,IAAI,CAAC;YAClB,mBAAmB,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;YACnE,gBAAgB,EAAE,CACjB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAChC,IAAI,CAAC;YACV,OAAO,EAAE;gBACR,QAAQ,EAAE,OAAO,CAAC;gBAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;aACvB,CAAC;SACF,CAAC;QACF,eAAe,CAAC,EAAE;YACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACvB,CAAC;KACF;CACD;AAED,MAAM,WAAW,uBAAuB;IACvC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAyDlE"}
@@ -0,0 +1,51 @@
1
+ function databuddy(options) {
2
+ const { script } = options;
3
+ const handleConsentOpt = (hasConsent)=>{
4
+ if (!window.databuddy) return;
5
+ if (hasConsent && window.databuddy.options.disabled) window.databuddy.options.disabled = false;
6
+ else if (!hasConsent && !window.databuddy.options.disabled) window.databuddy.options.disabled = true;
7
+ };
8
+ return {
9
+ id: script?.id ?? 'databuddy',
10
+ category: script?.category ?? 'measurement',
11
+ src: options.scriptUrl ?? 'https://cdn.databuddy.cc/databuddy.js',
12
+ async: true,
13
+ attributes: {
14
+ crossorigin: 'anonymous',
15
+ 'data-client-id': options.clientId,
16
+ ...options.apiUrl ? {
17
+ 'data-api-url': options.apiUrl
18
+ } : {}
19
+ },
20
+ alwaysLoad: true,
21
+ onBeforeLoad: ({ hasConsent, ...rest })=>{
22
+ if (!window.databuddyConfig) window.databuddyConfig = {
23
+ clientId: options.clientId,
24
+ ...options.apiUrl ? {
25
+ apiUrl: options.apiUrl
26
+ } : {},
27
+ ...options.options || {},
28
+ disabled: !hasConsent
29
+ };
30
+ script?.onBeforeLoad?.({
31
+ hasConsent,
32
+ ...rest
33
+ });
34
+ },
35
+ onLoad: ({ hasConsent, ...rest })=>{
36
+ if (window.databuddy) handleConsentOpt(hasConsent);
37
+ script?.onLoad?.({
38
+ hasConsent,
39
+ ...rest
40
+ });
41
+ },
42
+ onConsentChange: ({ hasConsent, ...rest })=>{
43
+ handleConsentOpt(hasConsent);
44
+ script?.onConsentChange?.({
45
+ hasConsent,
46
+ ...rest
47
+ });
48
+ }
49
+ };
50
+ }
51
+ export { databuddy };
@@ -1,4 +1,4 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__ from "./google-tag-manager.js";
1
+ import { DEFAULT_GTM_CONSENT_CONFIG, mapConsentStateToGTM } from "./google-tag-manager.js";
2
2
  function gtag({ id, script, category }) {
3
3
  return {
4
4
  ...script,
@@ -9,8 +9,8 @@ function gtag({ id, script, category }) {
9
9
  persistAfterConsentRevoked: true,
10
10
  alwaysLoad: true,
11
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);
12
+ let gtmConsent = DEFAULT_GTM_CONSENT_CONFIG;
13
+ if (consents) gtmConsent = mapConsentStateToGTM(consents);
14
14
  const setupScript = document.createElement("script");
15
15
  setupScript.id = `${elementId}-init`;
16
16
  setupScript.textContent = `
@@ -33,7 +33,7 @@ function gtag({ id, script, category }) {
33
33
  });
34
34
  },
35
35
  onConsentChange (args) {
36
- if (window.gtag) window.gtag('consent', 'update', (0, __WEBPACK_EXTERNAL_MODULE__google_tag_manager_js_a8e3fec2__.mapConsentStateToGTM)(args.consents));
36
+ if (window.gtag) window.gtag('consent', 'update', mapConsentStateToGTM(args.consents));
37
37
  if (script?.onConsentChange) script.onConsentChange(args);
38
38
  }
39
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c15t/scripts",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-canary-20251112105612",
4
4
  "description": "Pre-built scripts of popular tools for c15t's script loader.",
5
5
  "homepage": "https://c15t.com/docs/frameworks/javascript/script-loader",
6
6
  "repository": {
@@ -27,9 +27,9 @@
27
27
  "not op_mini all"
28
28
  ],
29
29
  "devDependencies": {
30
- "@c15t/typescript-config": "0.0.1-beta.1",
31
30
  "@c15t/vitest-config": "1.0.0",
32
- "c15t": "1.7.0"
31
+ "@c15t/typescript-config": "0.0.1-beta.1",
32
+ "c15t": "1.8.0-canary-20251112105612"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
package/readme.json CHANGED
@@ -8,5 +8,8 @@
8
8
  "Supported vendors include Google Tag Manager, Meta Pixel, PostHog, TikTok Pixel, LinkedIn Insights, Microsoft UET, and X Pixel"
9
9
  ],
10
10
  "docsLink": "https://c15t.com/docs/integrations",
11
- "showCLIGeneration": false
11
+ "showCLIGeneration": false,
12
+ "customSections": {
13
+ "Scripts": "- [Google Tag Manager](https://c15t.link/google-tag-manager)\n- [Google Tag](https://c15t.link/google-tag)\n- [PostHog](https://c15t.link/posthog)\n- [Meta Pixel](https://c15t.link/meta-pixel)\n- [TikTok Pixel](https://c15t.link/tiktok-pixel)\n- [LinkedIn Insights](https://c15t.link/linkedin-insights)\n- [Microsoft UET](https://c15t.link/microsoft-uet)\n- [X Pixel](https://c15t.link/x-pixel)"
14
+ }
12
15
  }