-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change
useTrackingScript
to createConsentPromise
- Loading branch information
Showing
6 changed files
with
68 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { ConsentPromiseOptions } from '../types' | ||
import { isDoNotTrackEnabled, isRef, onNuxtReady, ref, toValue, watch } from '#imports' | ||
|
||
export function createConsentTrigger(options: ConsentPromiseOptions) { | ||
return new Promise<void>((resolve) => { | ||
onNuxtReady(() => { | ||
const consented = ref<boolean>(false) | ||
// check if DNT is enabled, never consent | ||
if (options?.honourDoNotTrack && isDoNotTrackEnabled()) | ||
return | ||
if (options?.consent) { | ||
// check for boolean primitive | ||
if (typeof options?.consent === 'boolean') { | ||
consented.value = true | ||
} | ||
// consent is a promise | ||
else if (options?.consent instanceof Promise) { | ||
options?.consent.then((res) => { | ||
consented.value = typeof res === 'boolean' ? res : true | ||
}) | ||
} | ||
else if (isRef(options?.consent)) { | ||
watch(options.consent, (_val) => { | ||
const val = toValue(_val) | ||
if (typeof val === 'boolean') | ||
consented.value = val | ||
}, { immediate: true }) | ||
} | ||
} | ||
watch(consented, (ready) => { | ||
if (ready) | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters