Skip to content

Commit

Permalink
Merge pull request #27 from mxdvl/patch-1
Browse files Browse the repository at this point in the history
fix: Add `blockTrackingForMe` method
  • Loading branch information
derrickreimer authored Jan 17, 2022
2 parents 35bffce + de26dea commit 0e2eb1b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
interface Fathom {
blockTrackingForMe: typeof blockTrackingForMe;
enableTrackingForMe: typeof enableTrackingForMe;
trackPageview: (opts?: PageViewOptions) => void;
trackGoal: (code: string, cents: number) => void;
}
Expand All @@ -21,7 +23,8 @@ export type LoadOptions = {

type FathomCommand =
| { type: 'trackPageview'; opts: PageViewOptions | undefined }
| { type: 'trackGoal'; code: string; cents: number };
| { type: 'trackGoal'; code: string; cents: number }
| { type: 'blockTrackingForMe' | 'enableTrackingForMe' };

declare global {
interface Window {
Expand Down Expand Up @@ -58,6 +61,14 @@ const flushQueue = (): void => {
case 'trackGoal':
window.fathom.trackGoal(command.code, command.cents);
return;

case 'enableTrackingForMe' :
window.fathom.enableTrackingForMe();
return;

case 'blockTrackingForMe' :
window.fathom.blockTrackingForMe();
return;
}
});
window.__fathomClientQueue = [];
Expand Down Expand Up @@ -140,3 +151,23 @@ export const trackGoal = (code: string, cents: number) => {
enqueue({ type: 'trackGoal', code, cents });
}
};

/**
* See https://usefathom.com/docs/features/exclude
*/
export const blockTrackingForMe = (): void => {
if (window.fathom) {
window.fathom.blockTrackingForMe();
} else {
enqueue({ type: 'blockTrackingForMe' })
}
};

export const enableTrackingForMe = (): void => {
if (window.fathom) {
window.fathom.enableTrackingForMe();
} else {
enqueue({ type: 'enableTrackingForMe' })

}
};

0 comments on commit 0e2eb1b

Please sign in to comment.