Skip to content

Commit

Permalink
Consent - Do not load segment/send events unneccessarily (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Nov 18, 2023
1 parent a72f473 commit 57be1ac
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 65 deletions.
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...",
"test": "yarn jest",
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"build": "rm -rf dist && yarn concurrently 'yarn:build:*'",
Expand Down
Loading

0 comments on commit 57be1ac

Please sign in to comment.