diff --git a/README.md b/README.md index b0702491..8fdabe6a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ All the features from Unhead [useScript](https://unhead.unjs.io/usage/composable Plus Nuxt goodies: - ⏬ Serve third-party scripts from your own server -- 🕵️ Privacy Features - Trigger scripts loading on cookie consent, honour DoNotTrack. +- 🕵️ Privacy Features - Trigger scripts loading on consent. - 🪵 DevTools integration - View your script with their status and see function logs ## Background @@ -162,7 +162,6 @@ Creates a consent trigger for a script. #### Arguments - `consent` (optional) - A ref, promise, or boolean that resolves to the user's consent. Defaults to `undefined`. -- `honourDoNotTrack` (optional) - Respect the end-users browser Do Not Track option. Defaults to `false`. - `idle` (optional) - If consent is provided before the browser idle, wait for the browser to be idle before loading the script. Defaults to `false`. #### Returns @@ -195,20 +194,6 @@ const pageCtx = useAnalyticsPageEvent() pageCtx.value.title ``` -### `isDoNotTrackEnabled` - -**() => boolean** - -Check if the user's browser has Do Not Track enabled. On the server it will read the `DNT` header, and on the client it will read the `navigator.doNotTrack` property. - -#### Returns - -- `true` if Do Not Track is enabled, `false` otherwise. - -```ts -const dnt = isDoNotTrackEnabled() -``` - ## License Licensed under the [MIT license](https://github.com/nuxt/scripts/blob/main/LICENSE.md). diff --git a/src/runtime/composables/createScriptConsentTrigger.ts b/src/runtime/composables/createScriptConsentTrigger.ts index 36e245d3..edd1fd76 100644 --- a/src/runtime/composables/createScriptConsentTrigger.ts +++ b/src/runtime/composables/createScriptConsentTrigger.ts @@ -1,9 +1,11 @@ import type { ConsentPromiseOptions } from '../types' -import { isDoNotTrackEnabled, isRef, onNuxtReady, ref, requestIdleCallback, toValue, tryUseNuxtApp, watch } from '#imports' +import { isRef, onNuxtReady, ref, requestIdleCallback, toValue, tryUseNuxtApp, watch } from '#imports' -export function createScriptConsentTrigger(options?: ConsentPromiseOptions): { accept: () => void } & Promise { +type CreateScriptConsentTriggerApi = { accept: () => void } & Promise + +export function createScriptConsentTrigger(options?: ConsentPromiseOptions): CreateScriptConsentTriggerApi { if (import.meta.server) - return new Promise(() => {}) + return new Promise(() => {}) as CreateScriptConsentTriggerApi const consented = ref(false) // user may want ot still load the script on idle @@ -16,9 +18,6 @@ export function createScriptConsentTrigger(options?: ConsentPromiseOptions): { a runner(() => idleTimeout(resolve)) } }) - // check if DNT is enabled, never consent - if (options?.honourDoNotTrack && isDoNotTrackEnabled()) - return if (options?.consent) { // check for boolean primitive if (typeof options?.consent === 'boolean') { @@ -43,5 +42,5 @@ export function createScriptConsentTrigger(options?: ConsentPromiseOptions): { a promise.accept = () => { consented.value = true } - return promise + return promise as CreateScriptConsentTriggerApi } diff --git a/src/runtime/composables/isDoNotTrackEnabled.ts b/src/runtime/composables/isDoNotTrackEnabled.ts deleted file mode 100644 index 3b203069..00000000 --- a/src/runtime/composables/isDoNotTrackEnabled.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { useRequestHeader } from '#imports' - -const doNotTrackEnabledValues = [ - // account for all browsers and their different values - '1', // W3C standard - 'yes', // old standard - 'true', // old standard -] - -export function isDoNotTrackEnabled() { - if (import.meta.server) - return doNotTrackEnabledValues.includes(useRequestHeader('DNT') || '') - return doNotTrackEnabledValues.includes(window.navigator.doNotTrack || '') -} diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 616b9a22..f9781131 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -24,11 +24,6 @@ export interface ConsentPromiseOptions { * instead of using the accept() method. */ consent?: Promise | Ref | ComputedRef | boolean - /** - * The DoNotTrack property indicates that the user does not want to be tracked by the script. Most third-party scripts - * do not honour this property, however, you can opt in for improved privacy. - */ - honourDoNotTrack?: boolean /** * Should the script be loaded on the `requestIdleCallback` callback. This is useful for non-essential scripts that * have already been consented to be loaded.