Skip to content

Commit

Permalink
Add consent signal as dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaLeithy committed Oct 15, 2024
1 parent 385e671 commit 8b660ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/clarity-js/src/data/consent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Dimension } from "@clarity-types/data";
import * as dimension from "@src/data/dimension";

const enum ConsentType {
None = 0,
Implicit = 1,
General = 2
}

export function config(track: boolean): void {
trackConsent(track ? ConsentType.Implicit : ConsentType.None);
}

export function consent(consent: boolean): void {
trackConsent(consent ? ConsentType.General : ConsentType.None);
}

function trackConsent(consent: ConsentType): void {
dimension.log(Dimension.Consent, consent.toString());
}
6 changes: 6 additions & 0 deletions packages/clarity-js/src/data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as scrub from "@src/core/scrub";
import * as dimension from "@src/data/dimension";
import * as metric from "@src/data/metric";
import { set } from "@src/data/variable";
import * as trackConsent from "@src/data/consent";

export let data: Metadata = null;
export let callbacks: MetadataCallbackOptions[] = [];
Expand Down Expand Up @@ -74,6 +75,9 @@ export function start(): void {
if (value) { set(key, value); }
}

// Track consent config
trackConsent.config(config.track);

// Track ids using a cookie if configuration allows it
track(u);
}
Expand Down Expand Up @@ -127,9 +131,11 @@ export function consent(status: boolean = true): void {
return;
}

trackConsent.consent(status);
if (core.active()) {
config.track = true;
track(user(), BooleanFlag.True);
save();
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/clarity-js/types/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export const enum Dimension {
InitialScrollBottom = 32,
AncestorOrigins = 33,
Timezone = 34,
TimezoneOffset = 35
TimezoneOffset = 35,
Consent = 36
}

export const enum Check {
Expand Down

0 comments on commit 8b660ad

Please sign in to comment.