30 lines
853 B
TypeScript
30 lines
853 B
TypeScript
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";
|
|
}
|
|
}
|