Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix attribution to capture UTMs even if there is no referral info #584

Merged
merged 4 commits into from
Sep 15, 2023
Merged
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
9 changes: 7 additions & 2 deletions packages/plugin-web-attribution-browser/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const domainWithoutSubdomain = (domain: string) => {
return parts.slice(parts.length - 2, parts.length).join('.');
};

//Direct traffic mean no external referral, no UTMs, no click-ids, and no other customer identified marketing campaign url params.
const isDirectTraffic = (current: Campaign) => {
return Object.values(current).every((value) => !value);
};

export const isNewCampaign = (
current: Campaign,
previous: Campaign | undefined,
Expand All @@ -30,8 +35,8 @@ export const isNewCampaign = (
return false;
}

//In the same session, no referrer should not override or unset any persisting query params
if (!isNewSession && !referrer && previous) {
//In the same session, direct traffic should not override or unset any persisting query params
if (!isNewSession && isDirectTraffic(current) && previous) {
return false;
}

Expand Down
16 changes: 15 additions & 1 deletion packages/plugin-web-attribution-browser/test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('isNewCampaign', () => {
).toBe(false);
});

test('should return false for no referrer in the same session', () => {
test('should return false for no extra referrer with direct traffic in the same session', () => {
const previousCampaign = {
...BASE_CAMPAIGN,
utm_campaign: 'utm_campaign',
Expand All @@ -125,6 +125,20 @@ describe('isNewCampaign', () => {

expect(isNewCampaign(currentCampaign, previousCampaign, {}, false)).toBe(false);
});

test('should return true for no referrer with any new campaign in the same session', () => {
const previousCampaign = {
...BASE_CAMPAIGN,
utm_campaign: 'utm_campaign',
referring_domain: 'a.b.c.d',
kevinpagtakhan marked this conversation as resolved.
Show resolved Hide resolved
};
const currentCampaign = {
...BASE_CAMPAIGN,
utm_source: 'utm_source',
};

expect(isNewCampaign(currentCampaign, previousCampaign, {}, false)).toBe(true);
});
});

describe('isExcludedReferrer', () => {
Expand Down