Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ssr/src/lib/analytics/send-analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const sendAnalyticsEvents = async (
events: gaEvents,
awc: payload.awc,
channel: payload.awin_channel,
isTestmode: payload.awin_testmode === '1',
}));
}
if (metaEvents) {
Expand Down
8 changes: 8 additions & 0 deletions packages/ssr/src/lib/analytics/send-to-awin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ const sendToAwin = async ({
events,
awc,
channel = 'aw',
isTestmode,
}: {
events: AnalyticsEvent[],
awc?: string,
channel?: string,
isTestmode?: boolean,
}) => {
if (!awinAxios || !awc) return;
if (isTestmode) {
// This API has no test flag, any order posted here counts as a real
// conversion, so a test session must be left to the fallback pixel
logger.info('Skipping Awin S2S conversion on test mode session');
return;
}
const purchaseEvents = events.filter((ev) => ev.name === 'purchase');
if (!purchaseEvents.length) return;
const awinOrders: Array<Record<string, any>> = [];
Expand Down
11 changes: 11 additions & 0 deletions packages/storefront/src/analytics/set-tracking-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type TrackingIds = {
ttclid?: string,
awc?: string,
awin_channel?: string,
awin_testmode?: '1',
client_id?: string,
session_id?: string,
ip6?: string,
Expand Down Expand Up @@ -64,6 +65,16 @@ export const getTrackingIds = (
}
trackingIds[key] = value;
});
// The Awin conversion REST API has no test flag, every order it receives is
// real, so test transactions are marked on the session with
// `?awin_testmode=1`: the fallback pixel then fires with `testmode=1` and the
// server skips the S2S call, leaving the pixel as the only channel
if (url.searchParams.get('awin_testmode') === '1') {
sessionStorage.setItem('analytics_awin_testmode', '1');
}
if (sessionStorage.getItem('analytics_awin_testmode') === '1') {
trackingIds.awin_testmode = '1';
}
const cookieNames = ['_fbp', 'AwinChannelCookie'];
if (!trackingIds.fbc) cookieNames.push('_fbc');
if (!trackingIds.g_client_id) cookieNames.push('_ga');
Expand Down
13 changes: 9 additions & 4 deletions packages/storefront/src/lib/scripts/vbeta-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const emitAwinFallbackPixel = (orderRef: string, amount: number, coupon?: string
+ `&parts=${encodeURIComponent(`DEFAULT:${amount}`)}`
+ `&vc=${encodeURIComponent(coupon || '')}`
+ `&ch=${encodeURIComponent(trackingIds.awin_channel || 'aw')}`
+ '&testmode=0';
// Attributes the sale from the click id instead of Awin's own cookies,
// keeping the fallback deterministic when the S2S call doesn't arrive
+ `&cks=${encodeURIComponent(trackingIds.awc)}`
+ `&testmode=${trackingIds.awin_testmode === '1' ? '1' : '0'}`;
const img = new Image(0, 0);
img.src = src;
};
Expand Down Expand Up @@ -170,10 +173,12 @@ const watchAppRoutes = () => {
// With the S2S call active the pixel only fires when the client
// has the customer-facing number AND the real order amounts: a
// pixel with mismatched ref or amount could win Awin's dedup by
// reference over the accurate S2S conversion. Without S2S the
// pixel is the only channel, so it always fires falling back to
// the internal order ID and cart subtotal (legacy behavior)
// reference over the accurate S2S conversion. Without S2S -- either
// unset on the store or skipped on a test session -- the pixel is
// the only channel, so it always fires falling back to the internal
// order ID and cart subtotal (legacy behavior)
const canEmitAwinPixel = !window.AWIN_S2S_ENABLED
|| trackingIds.awin_testmode === '1'
|| (!!params.order_number && params.shipping !== undefined);
if (canEmitAwinPixel) {
// Awin expects the commissionable amount without freight and taxes
Expand Down