Skip to content

Commit

Permalink
fix: drop deprecated DoNotTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Mar 22, 2024
1 parent da29ca0 commit 24725e4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 42 deletions.
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
13 changes: 6 additions & 7 deletions src/runtime/composables/createScriptConsentTrigger.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
type CreateScriptConsentTriggerApi = { accept: () => void } & Promise<void>

export function createScriptConsentTrigger(options?: ConsentPromiseOptions): CreateScriptConsentTriggerApi {
if (import.meta.server)
return new Promise(() => {})
return new Promise(() => {}) as CreateScriptConsentTriggerApi

const consented = ref<boolean>(false)
// user may want ot still load the script on idle
Expand All @@ -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') {
Expand All @@ -43,5 +42,5 @@ export function createScriptConsentTrigger(options?: ConsentPromiseOptions): { a
promise.accept = () => {
consented.value = true
}
return promise
return promise as CreateScriptConsentTriggerApi
}
14 changes: 0 additions & 14 deletions src/runtime/composables/isDoNotTrackEnabled.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ export interface ConsentPromiseOptions {
* instead of using the accept() method.
*/
consent?: Promise<boolean | void> | Ref<boolean> | ComputedRef<boolean> | 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.
Expand Down

0 comments on commit 24725e4

Please sign in to comment.