@misiki/gocommerce-connector 0.19.0 → 0.21.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.
@@ -163,6 +163,17 @@ function currentMe() {
163
163
  return null;
164
164
  }
165
165
  }
166
+ function metaBrowser() {
167
+ const fbp = readCookie("_fbp");
168
+ if (!fbp || typeof window.fbq !== "function") return void 0;
169
+ const fbc = readCookie("_fbc");
170
+ return {
171
+ fbp,
172
+ ...fbc ? { fbc } : {},
173
+ client_user_agent: window.navigator.userAgent,
174
+ event_source_url: window.location.origin + window.location.pathname
175
+ };
176
+ }
166
177
  function storedCartId() {
167
178
  const v = readLocal("cart_id");
168
179
  if (!v || v === "undefined" || v === "null") return null;
@@ -2188,11 +2199,13 @@ var CheckoutService = class extends BaseService {
2188
2199
  ...extra
2189
2200
  };
2190
2201
  const serialised = JSON.stringify(body);
2191
- const key = extras.attempt?.body === `${code}:${serialised}` ? extras.attempt.key : newKey();
2192
- saveCartExtras(id2, { attempt: { key, body: `${code}:${serialised}` } });
2202
+ const retry = extras.attempt?.body === `${code}:${serialised}`;
2203
+ const key = retry ? extras.attempt.key : newKey();
2204
+ const meta = retry ? extras.attempt?.meta : metaBrowser();
2205
+ saveCartExtras(id2, { attempt: { key, body: `${code}:${serialised}`, ...meta ? { meta } : {} } });
2193
2206
  const result = await this.data(`/api/checkout/${encodeURIComponent(code)}`, {
2194
2207
  method: "POST",
2195
- body,
2208
+ body: meta ? { ...body, metadata: { ...extra.metadata, meta_capi: meta } } : body,
2196
2209
  headers: { "Idempotency-Key": key }
2197
2210
  });
2198
2211
  if (result.order.access_token) {
@@ -3151,6 +3164,11 @@ var StoreService = class extends BaseService {
3151
3164
  // The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
3152
3165
  // switch (D131) can only show it while that is on.
3153
3166
  newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
3167
+ // The ad and analytics tags (D160). The engine decides, not the static record:
3168
+ // one storefront serves every store, and one store's pixel must never
3169
+ // load on another's pages.
3170
+ ...adTags(plugins),
3171
+ googleTagManager: googleTags(plugins),
3154
3172
  // Discount codes are core: every GoCommerce store takes them, so
3155
3173
  // the code box is shown whatever the static record says.
3156
3174
  isDiscountCoupons: { ...basePlugins.isDiscountCoupons, active: true },
@@ -3176,6 +3194,32 @@ var StoreService = class extends BaseService {
3176
3194
  }
3177
3195
  };
3178
3196
  var storeService = new StoreService();
3197
+ var AD_TAGS = [
3198
+ ["meta-pixel", "pixel_id", "facebookPixel"],
3199
+ ["microsoft-clarity", "project_id", "microsoftClarity"],
3200
+ ["hotjar", "site_id", "hotjar"],
3201
+ ["tiktok-pixel", "pixel_id", "tiktokPixel"],
3202
+ ["pinterest-tag", "tag_id", "pinterestTag"],
3203
+ ["snapchat-pixel", "pixel_id", "snapchatPixel"]
3204
+ ];
3205
+ function adTags(plugins) {
3206
+ return Object.fromEntries(
3207
+ AD_TAGS.map(([key, field, name]) => {
3208
+ const id2 = String(plugins.get(key)?.settings?.[field] ?? "").trim();
3209
+ return [name, id2 ? { active: true, id: id2 } : { active: false }];
3210
+ })
3211
+ );
3212
+ }
3213
+ function googleTags(plugins) {
3214
+ const s = plugins.get("google-analytics")?.settings ?? {};
3215
+ const id2 = (field) => String(s[field] ?? "").trim();
3216
+ const [account, part] = id2("conversion_label").split("/");
3217
+ const label = part === void 0 ? account : part;
3218
+ const ads = id2("google_ads_id") || (part === void 0 ? "" : account);
3219
+ const tags = [id2("ga4_measurement_id"), ads, id2("gtm_container_id")].filter(Boolean);
3220
+ if (!tags.length) return { active: false };
3221
+ return { active: true, tags, conversions: ads && label ? [{ event: "purchase", label }] : [] };
3222
+ }
3179
3223
  function deliverable(base, ships) {
3180
3224
  if (ships.everywhere || !ships.countries.length) return {};
3181
3225
  const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));