@cartbase/storefront 0.6.0 → 0.8.0

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.
@@ -40,6 +40,10 @@ export type TrackingConfig = {
40
40
  /** Cartbase extension over the @1click TrackingConfig — explicit Google
41
41
  * Ads tag config (the @1click engine wired Ads through GTM). */
42
42
  googleAds?: { conversionId: string; conversionLabel?: string }
43
+ /** Pixel id ONLY. The Events API token stays on the platform and is
44
+ * read by the order.placed forwarder, exactly like Meta's CAPI token,
45
+ * which has never traversed this surface. */
46
+ tiktok?: { pixelId: string }
43
47
  /** True when the store's consent CMP is enabled — client tags must
44
48
  * mount through the consent gate (`_1c_consent` / Consent Mode v2). */
45
49
  consent_required?: boolean
@@ -171,6 +175,25 @@ export type TrackingAttribution = {
171
175
  utm_last_term?: string
172
176
  utm_last_content?: string
173
177
  utm_last_captured_at?: number
178
+
179
+ // ── Ad-click identifiers ───────────────────────────────────────────
180
+ // Captured by browser-side `captureClickIdsFromUrl()` into `_1c_`
181
+ // cookies and read here at checkout. Meta's fbclid needs no entry: it
182
+ // is folded into `fb_fbc` by Meta's own cookie format.
183
+
184
+ /** TikTok's click id. Without it TikTok cannot attribute a conversion
185
+ * back to the click that caused it. Sent as `user.ttclid`. */
186
+ tt_ttclid?: string
187
+ /** The `_ttp` cookie TikTok's own pixel writes when first-party
188
+ * cookies are enabled. Read only; sent as `user.ttp`. */
189
+ tt_ttp?: string
190
+ /** Google's standard click id. */
191
+ google_gclid?: string
192
+ /** iOS app-to-web click id. A campaign can deliver this instead of
193
+ * gclid, so capturing gclid alone loses that traffic silently. */
194
+ google_gbraid?: string
195
+ /** iOS web-to-web click id, same reasoning as gbraid. */
196
+ google_wbraid?: string
174
197
  }
175
198
 
176
199
  /**
@@ -0,0 +1,54 @@
1
+ "use client"
2
+
3
+ import { useEffect, useState } from "react"
4
+
5
+ import type { StorefrontClient } from "../api/http"
6
+ import { getTrackingConfig } from "./get-tracking-config"
7
+ import type { TrackingConfig } from "./types"
8
+
9
+ /**
10
+ * The store's public tag config, from a client component.
11
+ *
12
+ * `<StorefrontTags>` reads the same config on the SERVER, which is right
13
+ * for mounting tags in a layout. This hook exists for the one place that
14
+ * genuinely cannot: a client page that needs the config to decide what to
15
+ * send, the order confirmation being the case that matters, because
16
+ * Google Ads needs the account id and the purchase label to build a valid
17
+ * `send_to`.
18
+ *
19
+ * Cached per browser session in module scope: the config changes only
20
+ * when a merchant edits Settings → Integrations, and re-fetching it on
21
+ * every mount would put a request in front of the purchase event.
22
+ *
23
+ * Returns undefined until the fetch resolves, and `{}` if it fails, so a
24
+ * caller renders and fires the vendors that need no config either way.
25
+ */
26
+
27
+ let cached: TrackingConfig | undefined
28
+ let inFlight: Promise<TrackingConfig> | undefined
29
+
30
+ export function useTrackingConfig(
31
+ client: StorefrontClient
32
+ ): TrackingConfig | undefined {
33
+ const [config, setConfig] = useState<TrackingConfig | undefined>(cached)
34
+
35
+ useEffect(() => {
36
+ if (cached) return
37
+ let active = true
38
+ inFlight =
39
+ inFlight ??
40
+ getTrackingConfig(client).then((value) => {
41
+ cached = value
42
+ inFlight = undefined
43
+ return value
44
+ })
45
+ inFlight.then((value) => {
46
+ if (active) setConfig(value)
47
+ })
48
+ return () => {
49
+ active = false
50
+ }
51
+ }, [client])
52
+
53
+ return config
54
+ }