Repository navigation
feat: add persistTrackingPreference to let a consent tool own the tracking choice - #239
Merged
Merged
Conversation
…e use, and tracking after consent
…istence # Conflicts: # src/runtime/plugin.ts
…stence # Conflicts: # README.md # src/module.ts # src/runtime/plugin.ts # src/runtime/types.ts # test/package-fixture/consumer.mts # test/runtime-plugin.test.ts
…TrackingPreference
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
enableTracking()anddisableTracking()save the visitor's choice in localStorage, and on later visits a saved choice takes precedence overtrackingEnabled. A site that already records that choice in a consent tool then has two records that can disagree. When consent expires, or the visitor clears cookies but not localStorage, the savedtruekeeps tracking on although the consent tool no longer has consent.The new
persistTrackingPreferenceoption,trueby default, lets the consent tool be the only record. Withfalse, the module starts every page load fromtrackingEnabled, never saves the preference, and removes one saved under an earlier configuration so it doesn't stay on the device unused. The application callsenableTracking()on each page load that should be tracked, typically from a consent callback that reports the stored choice on load. WithtrackingEnabled: false, every page load starts disabled, the landing route is held as in #237, and the consent callback records it.The default keeps the current behavior, so tracking regardless of consent, and the README's
utm:before-trackconsent check, work as before.In the README, the Configuration table lists the option, and its
trackingEnabledrow now describes the preference each page load starts from. The tracking preferences section says that both methods save the preference and describes turning that off when a consent manager already remembers the choice. It recommends pairing the option withtrackingEnabled: false, because withtrackingEnabled: truethe landing page is recorded as the app mounts, usually before the consent tool reports, anddisableTracking()lasts only until the next page load. It also notes that turning the option off removes saved opt-outs, so the consent tool must already hold them. The storage table notes that the key isn't saved with the option off, and the consent section offers the option as an alternative to the consent check in the hook when the consent tool reports the stored choice on every page load. The Composable table'senableTracking()anddisableTracking()rows no longer say they save the preference, since that now depends on the option.This branch is based on #237, which changes the same README section, so its diff shows only this change. It can target
mainonce #237 is merged.Release note: the new
persistTrackingPreferenceoption can be set tofalseto stop saving the tracking preference in localStorage, sotrackingEnabledand your consent tool decide on every page load.Validation: two new unit tests in
test/runtime-plugin.test.tsfailed before the change, because with the option off a savedfalsestill turned tracking off and a saved preference stayed in localStorage. They pass now, along with a test of the default, in which the preference is saved and takes precedence overtrackingEnabledon the next visit. The existing browser tests that restore a saved opt-out across rendering modes still pass with the default. The package consumer fixture sets the new option, sotest:packagechecks that it is in the published types.pnpm test(166 passed, 1 skipped),pnpm lint --max-warnings 0,pnpm format:check,pnpm test:types, andpnpm test:packagepass.