Skip to content

Commit

Permalink
feat(index): ads reporting for 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed May 29, 2024
1 parent c75796c commit b6c2314
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const fflags = {
enabled: (flag, callback) => this.has(flag) && callback(),
disabled: (flag, callback) => !this.has(flag) && callback(),
onetrust: [543, 770, 1136],
ads: [1339],
email: [1339],
};

sampleRUM.baseURL = sampleRUM.baseURL || new URL('https://rum.hlx.page');
Expand Down Expand Up @@ -238,3 +240,32 @@ fflags.enabled('onetrust', () => {
}
}
});

fflags.enabled('ads', () => {
const networks = {
google: /gclid|gclsrc|wbraid|gbraid/,
doubleclick: /dclid/,
microsoft: /msclkid/,
facebook: /fb(cl|ad_|pxl_)id/,
twitter: /tw(clid|src|term)/,
linkedin: /li_fat_id/,
pinterest: /epik/,
tiktok: /ttclid/,
};
const params = Array.from(new URLSearchParams(window.location.search).keys());
Object.entries(networks).forEach(([network, regex]) => {
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param }));
});
});

fflags.enabled('email', () => {
const networks = {
mailchimp: /mc_(c|e)id/,
marketo: /mkt_tok/,

};
const params = Array.from(new URLSearchParams(window.location.search).keys());
Object.entries(networks).forEach(([network, regex]) => {
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param }));
});
});

0 comments on commit b6c2314

Please sign in to comment.