Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent - Do not load segment/send events unneccessarily #1001

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/calm-dancers-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@segment/analytics-consent-tools': minor
---
Segment will not load, or, if already loaded, will not send events to segment, if all of the following conditions are met:
1. No destinations without a consent mapping (consentSettings.hasUnmappedDestinations == false)

AND

2. User has not consented to any category present in the consentSettings.allCategories array.
5 changes: 5 additions & 0 deletions .changeset/tame-cooks-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

add hasUnmappedDestinations property to types
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@
var t = document.createElement('script')
t.type = 'text/javascript'
t.async = !0
t.src =
'https://cdn.segment.com/analytics.js/v1/' +
writeKey +
'/analytics.min.js'
t.src = '/node_modules/@segment/analytics-next/dist/umd/standalone.js'
var n = document.getElementsByTagName('script')[0]
n.parentNode.insertBefore(t, n)
analytics._loadOptions = e
Expand Down
5 changes: 1 addition & 4 deletions examples/standalone-playground/pages/index-consent.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@
var t = document.createElement('script')
t.type = 'text/javascript'
t.async = !0
t.src =
'https://cdn.segment.com/analytics.js/v1/' +
writeKey +
'/analytics.min.js'
t.src = '/node_modules/@segment/analytics-next/dist/umd/standalone.js'
var n = document.getElementsByTagName('script')[0]
n.parentNode.insertBefore(t, n)
analytics._loadOptions = e
Expand Down
7 changes: 6 additions & 1 deletion packages/browser/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ export interface LegacySettings {
*/
consentSettings?: {
/**
* All unique consent categories.
* All unique consent categories for enabled destinations.
* There can be categories in this array that are important for consent that are not included in any integration (e.g. 2 cloud mode categories).
* @example ["Analytics", "Advertising", "CAT001"]
*/
allCategories: string[]

/**
* Whether or not there are any unmapped destinations for enabled destinations.
*/
hasUnmappedDestinations: boolean
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/consent/consent-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"!**/test-helpers/**"
],
"scripts": {
".": "yarn run -T turbo run --filter=@segment/analytics-consent-tools",
".": "yarn run -T turbo run --filter=@segment/analytics-consent-tools...",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, when is this script run?

Copy link
Contributor Author

@silesky silesky Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a helper for local development. I think I wrote about in the docs under development. This makes it useful for "yarn . watch" (watch this and all of its dependencies).

Also, ...package-name watches dependents -- which might also be a useful alias. e.g "yarn ... watch"

Copy link
Contributor Author

@silesky silesky Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I take that back about local development: we do use this in CI to lazily build specific packages. :-)

"test": "yarn jest",
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"build": "rm -rf dist && yarn concurrently 'yarn:build:*'",
Expand Down
Loading