Skip to content

Commit 57be1ac

Browse files
authored
Consent - Do not load segment/send events unneccessarily (#1001)
1 parent a72f473 commit 57be1ac

File tree

11 files changed

+286
-65
lines changed

11 files changed

+286
-65
lines changed

.changeset/calm-dancers-happen.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@segment/analytics-consent-tools': minor
3+
---
4+
Segment will not load, or, if already loaded, will not send events to segment, if all of the following conditions are met:
5+
1. No destinations without a consent mapping (consentSettings.hasUnmappedDestinations == false)
6+
7+
AND
8+
9+
2. User has not consented to any category present in the consentSettings.allCategories array.

.changeset/tame-cooks-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
add hasUnmappedDestinations property to types

examples/standalone-playground/pages/index-consent-no-banner.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@
106106
var t = document.createElement('script')
107107
t.type = 'text/javascript'
108108
t.async = !0
109-
t.src =
110-
'https://cdn.segment.com/analytics.js/v1/' +
111-
writeKey +
112-
'/analytics.min.js'
109+
t.src = '/node_modules/@segment/analytics-next/dist/umd/standalone.js'
113110
var n = document.getElementsByTagName('script')[0]
114111
n.parentNode.insertBefore(t, n)
115112
analytics._loadOptions = e

examples/standalone-playground/pages/index-consent.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@
9494
var t = document.createElement('script')
9595
t.type = 'text/javascript'
9696
t.async = !0
97-
t.src =
98-
'https://cdn.segment.com/analytics.js/v1/' +
99-
writeKey +
100-
'/analytics.min.js'
97+
t.src = '/node_modules/@segment/analytics-next/dist/umd/standalone.js'
10198
var n = document.getElementsByTagName('script')[0]
10299
n.parentNode.insertBefore(t, n)
103100
analytics._loadOptions = e

packages/browser/src/browser/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ export interface LegacySettings {
9090
*/
9191
consentSettings?: {
9292
/**
93-
* All unique consent categories.
93+
* All unique consent categories for enabled destinations.
9494
* 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).
9595
* @example ["Analytics", "Advertising", "CAT001"]
9696
*/
9797
allCategories: string[]
98+
99+
/**
100+
* Whether or not there are any unmapped destinations for enabled destinations.
101+
*/
102+
hasUnmappedDestinations: boolean
98103
}
99104
}
100105

packages/consent/consent-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"!**/test-helpers/**"
1414
],
1515
"scripts": {
16-
".": "yarn run -T turbo run --filter=@segment/analytics-consent-tools",
16+
".": "yarn run -T turbo run --filter=@segment/analytics-consent-tools...",
1717
"test": "yarn jest",
1818
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
1919
"build": "rm -rf dist && yarn concurrently 'yarn:build:*'",

0 commit comments

Comments
 (0)