From 3e5e34fd0b61d91b264d80fca01e9f844685c04c Mon Sep 17 00:00:00 2001 From: Vitor Date: Thu, 30 Jul 2026 13:22:00 -0300 Subject: [PATCH 1/2] fix(storefront): Persist awc as a cookie so it survives a new tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Awin's own "last click direto" test scenario (affiliate click, then open a fresh tab and navigate directly) was losing the awc value because it was only ever stored in sessionStorage, which a manually opened tab does not inherit. The fallback-cookie read logic already existed but nothing wrote that cookie — now it does. --- packages/storefront/src/analytics/set-tracking-ids.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/storefront/src/analytics/set-tracking-ids.ts b/packages/storefront/src/analytics/set-tracking-ids.ts index 7fce605fc..eaf114adc 100644 --- a/packages/storefront/src/analytics/set-tracking-ids.ts +++ b/packages/storefront/src/analytics/set-tracking-ids.ts @@ -1,3 +1,5 @@ +import { setCookie } from '@@sf/sf-lib'; + export type TrackingIds = { gclid?: string, g_client_id?: string, @@ -48,6 +50,11 @@ export const getTrackingIds = ( if (id) { value = id; sessionStorage.setItem(`analytics_${key}`, id); + if (key === 'awc') { + // Persist as a real cookie (not just sessionStorage) so it survives + // a manually-opened new tab, per Awin's "last click direto" scenario + setCookie('awc', id, 30); + } } else { value = sessionStorage.getItem(`analytics_${key}`) || undefined; } From 10d22af315ed0d510f02f8f31e3c4cc70b9af7af Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Fri, 31 Jul 2026 19:58:49 -0300 Subject: [PATCH 2/2] chore(analytics): Make Awin tracking comments match the official docs Awin's Conversion API doc doesn't enumerate accepted "channel" values (channel is free-form and 'aw' is the mandated fallback), so stop claiming it does; point the fallback pixel to its actual doc page and trim change-narration comments down to the constraints they document. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01D6txsobQ3CPAo1yYK7XDab --- packages/ssr/src/lib/analytics/send-to-awin.ts | 2 +- packages/storefront/src/analytics/set-tracking-ids.ts | 3 +-- packages/storefront/src/lib/scripts/vbeta-app.ts | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/ssr/src/lib/analytics/send-to-awin.ts b/packages/ssr/src/lib/analytics/send-to-awin.ts index fceb5e964..5fe64f6b3 100644 --- a/packages/ssr/src/lib/analytics/send-to-awin.ts +++ b/packages/ssr/src/lib/analytics/send-to-awin.ts @@ -18,7 +18,7 @@ const awinAxios = AWIN_ADVERTISER_ID && AWIN_API_KEY }) : null; -// https://help.awin.com/apidocs/conversion-api - accepted "channel" values +// Expected AwinChannelCookie values — Awin docs mandate 'aw' as the fallback const validChannels = new Set([ 'aw', 'ppcgeneric', 'ppcbrand', 'display', 'social', 'Other', 'Organic', 'direct', ]); diff --git a/packages/storefront/src/analytics/set-tracking-ids.ts b/packages/storefront/src/analytics/set-tracking-ids.ts index eaf114adc..87f603f66 100644 --- a/packages/storefront/src/analytics/set-tracking-ids.ts +++ b/packages/storefront/src/analytics/set-tracking-ids.ts @@ -51,8 +51,7 @@ export const getTrackingIds = ( value = id; sessionStorage.setItem(`analytics_${key}`, id); if (key === 'awc') { - // Persist as a real cookie (not just sessionStorage) so it survives - // a manually-opened new tab, per Awin's "last click direto" scenario + // Awin prescribes an awc cookie; sessionStorage doesn't survive a manually-opened tab setCookie('awc', id, 30); } } else { diff --git a/packages/storefront/src/lib/scripts/vbeta-app.ts b/packages/storefront/src/lib/scripts/vbeta-app.ts index 7b7f68ea5..e7a45e125 100644 --- a/packages/storefront/src/lib/scripts/vbeta-app.ts +++ b/packages/storefront/src/lib/scripts/vbeta-app.ts @@ -29,8 +29,8 @@ import { shoppingCart } from '@@sf/state/shopping-cart'; import { emitGtagEvent, getGtagItem, trackingIds } from '@@sf/state/use-analytics'; import utm from '@@sf/scripts/session-utm'; -// https://help.awin.com/apidocs - fallback pixel, redundant to the server-to-server -// Conversion API call already made from send-to-awin.ts +// https://help.awin.com/developers/docs/fall-back-conversion-pixel +// Awin prioritizes one tracking method per order ref, no double-count with the S2S call const emitAwinFallbackPixel = (orderId: string, amount: number, coupon?: string) => { if (!window.AWIN_ADVERTISER_ID || !trackingIds.awc) return; const src = 'https://www.awin1.com/sread.img'