Initial Commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type {
|
||||
AnalyticsEvent,
|
||||
ConsentPolicy,
|
||||
} from "../types/analytics.types.js";
|
||||
|
||||
/**
|
||||
* Permits every event. Default policy when none is supplied to the
|
||||
* tracker.
|
||||
*/
|
||||
export class AllowAllPolicy implements ConsentPolicy {
|
||||
public isAllowed(_event: AnalyticsEvent): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Honours the host's `Do Not Track` signal. Blocks every event when
|
||||
* `navigator.doNotTrack === "1"`, otherwise permits every event. Reads
|
||||
* the navigator lazily inside `isAllowed` so the policy is constructable
|
||||
* in SSR / Node contexts where `navigator` does not exist.
|
||||
*/
|
||||
export class DoNotTrackPolicy implements ConsentPolicy {
|
||||
public isAllowed(_event: AnalyticsEvent): boolean {
|
||||
if (typeof navigator === "undefined") {
|
||||
return true;
|
||||
}
|
||||
return navigator.doNotTrack !== "1";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user