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

TW-1252: Cashback services domains tracking #1048

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review fix
  • Loading branch information
lendihop committed Jan 10, 2024
commit 64277d07e6b1bc744daaa71695ccbef6530c8f99
8 changes: 7 additions & 1 deletion src/lib/temple/back/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ const processRequest = async (req: TempleRequest, port: Runtime.Port): Promise<T
browser.runtime.onMessage.addListener(msg => {
switch (msg?.type) {
case ContentScriptType.ExternalLinksActivity:
const trackedCashbackServiceDomain = getTrackedCashbackServiceDomain(new URL(msg.url).hostname);
let { hostname } = new URL(msg.url);

if (hostname.startsWith('www')) {
hostname = hostname.slice(4);
}

const trackedCashbackServiceDomain = getTrackedCashbackServiceDomain(hostname);

if (trackedCashbackServiceDomain) {
Analytics.client.track('External Cashback Links Activity', { domain: trackedCashbackServiceDomain });
Expand Down
13 changes: 2 additions & 11 deletions src/lib/utils/url-track/url-track.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,8 @@ export const getTrackedUrl = (actualUrl: string) => {
return null;
};

export const getTrackedCashbackServiceDomain = (hostname: string) => {
for (let i = 0; i < CASHBACK_SERVICES_DOMAINS.length; i++) {
const currentDomain = CASHBACK_SERVICES_DOMAINS[i];

if (hostname.endsWith(currentDomain)) {
return currentDomain;
}
}

return null;
};
export const getTrackedCashbackServiceDomain = (hostname: string) =>
CASHBACK_SERVICES_DOMAINS.find(domain => domain === hostname);

const transformTzktUrl = (url: string) => {
const splittedUrl = url.split('/');
Expand Down
Loading