@escape-game-over/atlas 0.1.57 → 0.1.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escape-game-over/atlas",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "type": "module",
5
5
  "description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
6
6
  "private": false,
@@ -0,0 +1,20 @@
1
+ import { warn } from "../warn.ts";
2
+ import { UUID } from "./snap-pixel.ts";
3
+
4
+ /** AppLovin's Axon pixel. Marketing: it loads only once a visitor grants that. */
5
+ export interface AxonPixelSettings {
6
+ /** From the Axon dashboard: a UUID. */
7
+ readonly eventKey: string;
8
+ }
9
+
10
+ /** Warns about a key that is not an event key: it would report nowhere. */
11
+ export function checkAxonPixel(
12
+ axon: AxonPixelSettings | undefined,
13
+ at: string
14
+ ): void {
15
+ if (axon === undefined || UUID.test(axon.eventKey)) return;
16
+ warn(
17
+ at,
18
+ `Axon event key "${axon.eventKey}" is not a UUID, so it reports nowhere. Copy it from the Axon dashboard.`
19
+ );
20
+ }
@@ -0,0 +1,16 @@
1
+ import { warn } from "../warn.ts";
2
+
3
+ /** Drip's site tracking. Marketing: it loads only once a visitor grants that. */
4
+ export interface DripSettings {
5
+ /** From Drip's Site Setup: digits, the `_dcs.account` of its snippet. */
6
+ readonly accountId: string;
7
+ }
8
+
9
+ /** Warns about an id that is not an account id: it would report nowhere. */
10
+ export function checkDrip(drip: DripSettings | undefined, at: string): void {
11
+ if (drip === undefined || /^\d+$/.test(drip.accountId)) return;
12
+ warn(
13
+ at,
14
+ `Drip account id "${drip.accountId}" is not all digits, so it reports nowhere. Copy it from Drip's Site Setup.`
15
+ );
16
+ }
@@ -1,5 +1,7 @@
1
1
  import type { MetaTag } from "../meta/tag.ts";
2
2
  import type { HttpsUrl } from "../url.ts";
3
+ import { type AxonPixelSettings, checkAxonPixel } from "./axon-pixel.ts";
4
+ import { checkDrip, type DripSettings } from "./drip.ts";
3
5
  import { type GoogleSettings, googleEmits, googleScripts } from "./google.ts";
4
6
  import { checkMetaPixel, type MetaPixelSettings } from "./meta-pixel.ts";
5
7
  import { checkSnapPixel, type SnapPixelSettings } from "./snap-pixel.ts";
@@ -26,6 +28,8 @@ import {
26
28
  * project states ids; lib decides everything that follows from them.
27
29
  */
28
30
 
31
+ export type { AxonPixelSettings } from "./axon-pixel.ts";
32
+ export type { DripSettings } from "./drip.ts";
29
33
  export {
30
34
  CONSENT_UPDATE_GLOBAL,
31
35
  type ConsentDefaults,
@@ -52,6 +56,10 @@ export interface AnalyticsSettings {
52
56
  readonly tiktok?: TikTokPixelSettings;
53
57
  /** Loaded by `ConsentBanner`, after marketing is granted. */
54
58
  readonly snapchat?: SnapPixelSettings;
59
+ /** Loaded by `ConsentBanner`, after marketing is granted. */
60
+ readonly axon?: AxonPixelSettings;
61
+ /** Loaded by `ConsentBanner`, after marketing is granted. */
62
+ readonly drip?: DripSettings;
55
63
  }
56
64
 
57
65
  /**
@@ -75,6 +83,8 @@ export function analyticsScripts(
75
83
  checkMetaPixel(analytics.meta, origin);
76
84
  checkTikTokPixel(analytics.tiktok, origin);
77
85
  checkSnapPixel(analytics.snapchat, origin);
86
+ checkAxonPixel(analytics.axon, origin);
87
+ checkDrip(analytics.drip, origin);
78
88
  const google = googleScripts(analytics.google, origin);
79
89
  return {
80
90
  head: [...google.head, ...umamiScripts(analytics.umami)],
@@ -119,6 +129,10 @@ export function consentVendors(
119
129
  tiktok: analytics.tiktok !== undefined,
120
130
  // No consent mode at all.
121
131
  snapchat: analytics.snapchat !== undefined,
132
+ // No consent mode at all.
133
+ axon: analytics.axon !== undefined,
134
+ // No consent mode at all.
135
+ drip: analytics.drip !== undefined,
122
136
  };
123
137
 
124
138
  return (Object.keys(VENDORS) as (keyof AnalyticsSettings)[]).filter(
@@ -7,7 +7,8 @@ export interface SnapPixelSettings {
7
7
  readonly pixelIds: NonEmpty<string>;
8
8
  }
9
9
 
10
- const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ export const UUID =
11
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
11
12
 
12
13
  /** Warns about an id that is not a pixel id: it would report nowhere. */
13
14
  export function checkSnapPixel(
@@ -0,0 +1,18 @@
1
+ ---
2
+ /** Internal to `ConsentBanner.astro`, so the pixel's script ships only where it is configured. */
3
+ import type { AxonPixelSettings } from "../analytics/axon-pixel.ts";
4
+ import AtlasElement from "./AtlasElement.astro";
5
+ import { axonPixelElement } from "./axon-pixel.ts";
6
+
7
+ interface Props {
8
+ readonly settings: AxonPixelSettings;
9
+ }
10
+ ---
11
+
12
+ <script src="./axon-pixel.ts" />
13
+
14
+ <AtlasElement
15
+ of={axonPixelElement}
16
+ data-event-key={Astro.props.settings.eventKey}
17
+ hidden
18
+ />
@@ -5,12 +5,14 @@
5
5
  * buttons.
6
6
  *
7
7
  * Renders nothing — and ships no script — when this site's analytics need no
8
- * permission. Also loads the vendors that wait for consent, such as the Meta, TikTok and Snap pixels. Otherwise the banner starts hidden and shows only to a visitor
8
+ * permission. Also loads the vendors that wait for consent, such as the Meta, TikTok, Snap and Axon pixels and Drip. Otherwise the banner starts hidden and shows only to a visitor
9
9
  * with no answer on record, or when a `data-consent-reopen` control is pressed.
10
10
  */
11
11
  import type { HTMLAttributes } from "astro/types";
12
12
  import { type AnalyticsSettings, consentRequired } from "../analytics/index.ts";
13
+ import AxonPixel from "./AxonPixel.astro";
13
14
  import ConsentElement from "./ConsentElement.astro";
15
+ import Drip from "./Drip.astro";
14
16
  import MetaPixel from "./MetaPixel.astro";
15
17
  import SnapPixel from "./SnapPixel.astro";
16
18
  import TikTokPixel from "./TikTokPixel.astro";
@@ -30,5 +32,7 @@ const { analytics, ...attrs } = Astro.props;
30
32
  {analytics?.meta && <MetaPixel settings={analytics.meta} />}
31
33
  {analytics?.tiktok && <TikTokPixel settings={analytics.tiktok} />}
32
34
  {analytics?.snapchat && <SnapPixel settings={analytics.snapchat} />}
35
+ {analytics?.axon && <AxonPixel settings={analytics.axon} />}
36
+ {analytics?.drip && <Drip settings={analytics.drip} />}
33
37
  </>
34
38
  )}
@@ -0,0 +1,18 @@
1
+ ---
2
+ /** Internal to `ConsentBanner.astro`, so Drip's script ships only where it is configured. */
3
+ import type { DripSettings } from "../analytics/drip.ts";
4
+ import AtlasElement from "./AtlasElement.astro";
5
+ import { dripElement } from "./drip.ts";
6
+
7
+ interface Props {
8
+ readonly settings: DripSettings;
9
+ }
10
+ ---
11
+
12
+ <script src="./drip.ts" />
13
+
14
+ <AtlasElement
15
+ of={dripElement}
16
+ data-account-id={Astro.props.settings.accountId}
17
+ hidden
18
+ />
@@ -0,0 +1,34 @@
1
+ import type { CurrencyCode } from "../money.ts";
2
+ import { readConsent } from "./consent.ts";
3
+
4
+ /**
5
+ * Axon's events that a site without a cart sends. The cart and purchase events
6
+ * are left out: Axon requires line items for them, and the visitor's email or
7
+ * phone for `purchase`.
8
+ */
9
+ export type AxonEvent = "generate_lead" | "sign_up" | "login" | "subscribe";
10
+
11
+ /** What the visitor chose, never who they are. */
12
+ export interface AxonEventData {
13
+ readonly value?: number;
14
+ readonly currency?: CurrencyCode;
15
+ }
16
+
17
+ /** What `axon-pixel.ts` defines once marketing is granted. */
18
+ interface AxonWindow {
19
+ axon?: (...args: unknown[]) => void;
20
+ }
21
+
22
+ /**
23
+ * Records an event with Axon's pixel — a lead sent, an account made.
24
+ *
25
+ * Dropped unless the pixel loaded and marketing is still granted: Axon has no
26
+ * consent call of its own, so the check is here. An analytics call must never
27
+ * be the reason a page misbehaves, so a dropped event is silent.
28
+ */
29
+ export function axonEvent(event: AxonEvent, data?: AxonEventData): void {
30
+ if (readConsent()?.marketing !== "granted") return;
31
+ const axon = (window as unknown as AxonWindow).axon;
32
+ if (data === undefined) axon?.("track", event);
33
+ else axon?.("track", event, data);
34
+ }
@@ -0,0 +1,72 @@
1
+ import { appendScript } from "./append-script.ts";
2
+ import type { ConsentGated } from "./consent-gate.ts";
3
+ import { whenGranted } from "./consent-gate.ts";
4
+ import { element } from "./element.ts";
5
+ import { data } from "./ref.ts";
6
+
7
+ /** Axon's `axon`: a queue until its scripts arrive and replay it. */
8
+ interface Axon {
9
+ (...args: unknown[]): void;
10
+ performOperation?: (...args: unknown[]) => void;
11
+ operationQueue: unknown[];
12
+ ts: number;
13
+ eventKey: string;
14
+ }
15
+
16
+ interface PixelWindow {
17
+ axon?: Axon;
18
+ }
19
+
20
+ const SCRIPTS = [
21
+ "https://s.axon.ai/pixel.js",
22
+ "https://res4.applovin.com/p/l/loader.iife.js",
23
+ ];
24
+
25
+ /** Axon's own base code, as it defines `axon` before the scripts load. */
26
+ function defineAxon(eventKey: string): Axon {
27
+ const global = window as unknown as PixelWindow;
28
+ if (global.axon !== undefined) return global.axon;
29
+ // `arguments` is the list of whatever a call passed, which every regular
30
+ // `function` gets without declaring it (an arrow function does not). The
31
+ // queue stores that object rather than an array because Axon's official
32
+ // snippet does: it is the shape Axon promises its script will replay.
33
+ const axon = function () {
34
+ // biome-ignore lint/complexity/noArguments: see above.
35
+ const args = arguments;
36
+ if (axon.performOperation)
37
+ Reflect.apply(axon.performOperation, axon, args);
38
+ else axon.operationQueue.push(args);
39
+ } as Axon;
40
+ axon.operationQueue = [];
41
+ axon.ts = Date.now();
42
+ axon.eventKey = eventKey;
43
+ global.axon = axon;
44
+ for (const src of SCRIPTS) appendScript(src);
45
+ return axon;
46
+ }
47
+
48
+ /**
49
+ * The pixel, loaded on the first grant. Axon has no consent call, so a
50
+ * withdrawal cannot pause what already loaded: `axonEvent` stops sending, and
51
+ * the next page does not load it.
52
+ */
53
+ export function axonPixel(eventKey: string): ConsentGated {
54
+ let loaded = false;
55
+ return {
56
+ grant: () => {
57
+ if (loaded) return;
58
+ loaded = true;
59
+ const axon = defineAxon(eventKey);
60
+ axon("init");
61
+ axon("track", "page_view");
62
+ },
63
+ };
64
+ }
65
+
66
+ /** Internal to `AxonPixel.astro`. */
67
+ export const axonPixelElement = element(
68
+ "atlas-axon-pixel",
69
+ ({ root, signal }) => {
70
+ whenGranted("marketing", axonPixel(data(root, "event-key")), signal);
71
+ }
72
+ );
@@ -10,11 +10,13 @@
10
10
  */
11
11
 
12
12
  export * from "./attribution.ts";
13
+ export * from "./axon-event.ts";
13
14
  export * from "./background-video.ts";
14
15
  export * from "./carousel.ts";
15
16
  // Reading only: a form that reports what the visitor agreed to. Recording an
16
17
  // answer stays with the banner.
17
18
  export { type ConsentRecord, readConsent } from "./consent.ts";
19
+ export * from "./drip-event.ts";
18
20
  export {
19
21
  type Connect,
20
22
  type ElementContext,
@@ -0,0 +1,24 @@
1
+ import { readConsent } from "./consent.ts";
2
+
3
+ /** What `drip.ts` defines once marketing is granted. */
4
+ interface DripWindow {
5
+ _dcq?: unknown[][];
6
+ }
7
+
8
+ /**
9
+ * Records an event with Drip, to start a workflow — a lead sent, a voucher
10
+ * bought. Drip's events are named by the site, so any name goes.
11
+ *
12
+ * Dropped unless Drip loaded and marketing is still granted: Drip has no
13
+ * consent call of its own, so the check is here. An analytics call must never
14
+ * be the reason a page misbehaves, so a dropped event is silent.
15
+ */
16
+ export function dripEvent(
17
+ action: string,
18
+ properties?: Readonly<Record<string, string | number | boolean>>
19
+ ): void {
20
+ if (readConsent()?.marketing !== "granted") return;
21
+ const queue = (window as unknown as DripWindow)._dcq;
22
+ if (properties === undefined) queue?.push(["track", action]);
23
+ else queue?.push(["track", action, properties]);
24
+ }
@@ -0,0 +1,37 @@
1
+ import { appendScript } from "./append-script.ts";
2
+ import type { ConsentGated } from "./consent-gate.ts";
3
+ import { whenGranted } from "./consent-gate.ts";
4
+ import { element } from "./element.ts";
5
+ import { data } from "./ref.ts";
6
+
7
+ /** Drip's globals: a queue of calls, and the account its script reports to. */
8
+ interface DripWindow {
9
+ _dcq?: unknown[][];
10
+ _dcs?: { account?: string };
11
+ }
12
+
13
+ /**
14
+ * Drip, loaded on the first grant. Its script records visits by itself, so
15
+ * nothing is queued here. Drip has no consent call, so a withdrawal cannot
16
+ * pause what already loaded: `dripEvent` stops sending, and the next page does
17
+ * not load it.
18
+ */
19
+ export function drip(accountId: string): ConsentGated {
20
+ let loaded = false;
21
+ return {
22
+ grant: () => {
23
+ if (loaded) return;
24
+ loaded = true;
25
+ const global = window as unknown as DripWindow;
26
+ global._dcq ??= [];
27
+ global._dcs ??= {};
28
+ global._dcs.account = accountId;
29
+ appendScript(`https://tag.getdrip.com/${accountId}.js`);
30
+ },
31
+ };
32
+ }
33
+
34
+ /** Internal to `Drip.astro`. */
35
+ export const dripElement = element("atlas-drip", ({ root, signal }) => {
36
+ whenGranted("marketing", drip(data(root, "account-id")), signal);
37
+ });
package/src/index.ts CHANGED
@@ -22,11 +22,13 @@ export {
22
22
  export {
23
23
  type AnalyticsSettings,
24
24
  type AnalyticsTags,
25
+ type AxonPixelSettings,
25
26
  CONSENT_UPDATE_GLOBAL,
26
27
  type ConsentDefaults,
27
28
  type ConsentState,
28
29
  consentRequired,
29
30
  consentVendors,
31
+ type DripSettings,
30
32
  type GoogleSettings,
31
33
  type MetaPixelSettings,
32
34
  type SnapPixelSettings,