@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.
- package/README.md +74 -58
- package/package.json +248 -233
- package/src/api/carts.ts +16 -1
- package/src/api/http.ts +17 -9
- package/src/api/index.ts +1 -0
- package/src/api/integrations.ts +118 -117
- package/src/api/store.ts +35 -0
- package/src/checkout/geocode.ts +1 -1
- package/src/lib/cookie-names.ts +45 -0
- package/src/lib/platform.ts +13 -0
- package/src/lib/visitor.ts +74 -0
- package/src/tracking/attribution.ts +153 -11
- package/src/tracking/consent.ts +14 -0
- package/src/tracking/events.ts +294 -0
- package/src/tracking/ga4.tsx +93 -49
- package/src/tracking/get-tracking-attribution.ts +46 -3
- package/src/tracking/google-ads.ts +84 -0
- package/src/tracking/gtag.ts +26 -13
- package/src/tracking/gtm.tsx +60 -0
- package/src/tracking/index.ts +187 -133
- package/src/tracking/inline-script.ts +49 -0
- package/src/tracking/live-heartbeat.tsx +63 -0
- package/src/tracking/page-views.tsx +96 -0
- package/src/tracking/storefront-tags.tsx +75 -0
- package/src/tracking/tiktok-pixel.tsx +83 -0
- package/src/tracking/track-init.tsx +56 -0
- package/src/tracking/track-order-purchase.tsx +122 -0
- package/src/tracking/ttq.ts +180 -0
- package/src/tracking/types.ts +23 -0
- package/src/tracking/use-tracking-config.ts +54 -0
package/src/tracking/types.ts
CHANGED
|
@@ -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
|
+
}
|