From 7a4fbec652e505df0ca0a7aa367533d26ff0776e Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:33:42 -0500 Subject: [PATCH 1/9] Update changeset --- .changeset/mean-apricots-hammer.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/mean-apricots-hammer.md b/.changeset/mean-apricots-hammer.md index 76b8b9065..3b2c1d7ff 100644 --- a/.changeset/mean-apricots-hammer.md +++ b/.changeset/mean-apricots-hammer.md @@ -1,6 +1,5 @@ --- '@segment/analytics-next': minor -'@segment/analytics-core': minor --- Adds `globalAnalyticsKey` option for setting custom global window buffers From 0a8c30a052943bafd12ee66c41623eaece6f7ec6 Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Thu, 14 Sep 2023 01:53:02 -0500 Subject: [PATCH 2/9] [docs] Update Node.js README.md --- packages/node/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/README.md b/packages/node/README.md index 81345659e..f24687291 100644 --- a/packages/node/README.md +++ b/packages/node/README.md @@ -103,7 +103,7 @@ import { Analytics } from '@segment/analytics-node'; import { NextRequest, NextResponse } from 'next/server'; export const analytics = new Analytics({ - writeKey: 'DjTUVRhleGaZX31JQpj6XIAaprCIb25W', + writeKey: '', maxEventsInBatch: 1, }) .on('error', console.error) From fcf42f68b4226b55417bbaeb6305d33129ede96d Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Thu, 14 Sep 2023 17:05:00 -0500 Subject: [PATCH 3/9] [Fix] Export UniversalStorage from @segment/analytics-next (#949) --- .changeset/clean-elephants-deny.md | 5 +++++ packages/browser/src/index.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/clean-elephants-deny.md diff --git a/.changeset/clean-elephants-deny.md b/.changeset/clean-elephants-deny.md new file mode 100644 index 000000000..c4e1fd79f --- /dev/null +++ b/.changeset/clean-elephants-deny.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-next': patch +--- + +Fix regression where we no longer export UniversalStorage (used in destinations) diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 625d8e91a..fdd552aa8 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -10,3 +10,4 @@ export * from './core/user' export type { AnalyticsSnippet } from './browser/standalone-interface' export type { MiddlewareFunction } from './plugins/middleware' export { getGlobalAnalytics } from './lib/global-analytics-helper' +export { UniversalStorage, Store, StorageObject } from './core/storage' From cb56224388d94936859f469c6639dd6eb50e3d4a Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Tue, 19 Sep 2023 08:06:59 -0500 Subject: [PATCH 4/9] [chore] Consent - shorten test command + make consistent (#951) --- .github/workflows/ci.yml | 2 +- packages/consent/consent-tools-integration-tests/README.md | 2 +- packages/consent/consent-tools-integration-tests/package.json | 2 +- turbo.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74a89229b..6bd3821a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - - run: yarn turbo run --filter='consent-tools-integration-tests' test:intg + - run: yarn turbo run --filter='consent-tools-integration-tests' test:int diff --git a/packages/consent/consent-tools-integration-tests/README.md b/packages/consent/consent-tools-integration-tests/README.md index e10909e33..65e606551 100644 --- a/packages/consent/consent-tools-integration-tests/README.md +++ b/packages/consent/consent-tools-integration-tests/README.md @@ -16,5 +16,5 @@ Why is this using wd.io instead of playwright? ## Development ### Build, start server, run tests (and exit gracefully) ``` -yarn . test:intg +yarn . test:int ``` diff --git a/packages/consent/consent-tools-integration-tests/package.json b/packages/consent/consent-tools-integration-tests/package.json index 7511b9245..7b8933df1 100644 --- a/packages/consent/consent-tools-integration-tests/package.json +++ b/packages/consent/consent-tools-integration-tests/package.json @@ -3,7 +3,7 @@ "private": true, "scripts": { ".": "yarn run -T turbo run --filter=@internal/consent-tools-integration-tests...", - "test:intg": "yarn wdio:local", + "test:int": "yarn wdio:local", "build": "webpack", "watch": "yarn build --watch", "wdio:local": "wdio wdio.conf.local.ts", diff --git a/turbo.json b/turbo.json index 8c818c5ac..aa1a3925b 100644 --- a/turbo.json +++ b/turbo.json @@ -14,7 +14,7 @@ "test": { "dependsOn": ["build"] }, - "test:intg": { + "test:int": { "dependsOn": ["build"] }, "watch": { From b49ed5f8194e53c581a4249a4f8578ba9153946c Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:16:00 -0500 Subject: [PATCH 5/9] [docs/test] Tweak consent tests / update docs (#954) --- .../consent-tools-vanilla/index.ts | 6 +--- .../src/page-objects/base-page.ts | 4 +-- .../src/tests/consent-tools-vanilla.test.ts | 9 ++++-- .../src/tests/onetrust.test.ts | 5 +-- packages/consent/consent-tools/README.md | 32 +++++++++++++------ .../consent-wrapper-onetrust/README.md | 2 +- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts b/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts index 5e56c29b3..f04602e81 100644 --- a/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts +++ b/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts @@ -1,14 +1,10 @@ import { AnalyticsBrowser } from '@segment/analytics-next' import { createWrapper } from '@segment/analytics-consent-tools' -const fakeCategories = { Advertising: true, Analytics: true } +const fakeCategories = { FooCategory1: true, FooCategory2: true } const withCMP = createWrapper({ getCategories: () => fakeCategories, - integrationCategoryMappings: { - Fullstory: ['Analytics'], - 'Actions Amplitude': ['Advertising'], - }, }) const analytics = new AnalyticsBrowser() diff --git a/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts b/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts index 569028cce..0da5da67d 100644 --- a/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts +++ b/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts @@ -36,13 +36,13 @@ export abstract class BasePage { { creationName: 'FullStory', consentSettings: { - categories: ['Analytics'], + categories: ['FooCategory2'], }, }, { creationName: 'Actions Amplitude', consentSettings: { - categories: ['Advertising'], + categories: ['FooCategory1'], }, } ) diff --git a/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts index 62c9c1154..2043ecdf0 100644 --- a/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts +++ b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts @@ -1,7 +1,10 @@ +/** + * Tests targeting @segment/analytics-consent-tools + */ + import page from '../page-objects/consent-tools-vanilla' import { expect } from 'expect' -// Verify that the consent tools wrapper is working as expected (no OneTrust) it('should stamp each event', async () => { await page.load() @@ -11,8 +14,8 @@ it('should stamp each event', async () => { expect((ctx.event.context as any).consent).toEqual({ categoryPreferences: { - Advertising: true, - Analytics: true, + FooCategory1: true, + FooCategory2: true, }, }) }) diff --git a/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts b/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts index 40b73aa76..bc8d2227c 100644 --- a/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts +++ b/packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts @@ -1,6 +1,7 @@ -// Verify that @segment/analytics-consent-wrapper-onetrust is working as expected +/** + * Tests targeting @segment/analytics-consent-wrapper-onetrust + */ -/* eslint-disable @typescript-eslint/no-floating-promises */ import page from '../page-objects/onetrust' import { expect } from 'expect' diff --git a/packages/consent/consent-tools/README.md b/packages/consent/consent-tools/README.md index a9fa8ac3d..7c851378c 100644 --- a/packages/consent/consent-tools/README.md +++ b/packages/consent/consent-tools/README.md @@ -7,23 +7,41 @@ import { createWrapper, resolveWhen } from '@segment/analytics-consent-tools' export const withCMP = createWrapper({ + + // Do not attempt to load segment until this function returns / resolves shouldLoad: (ctx) => { + const CMP = await getCMP() await resolveWhen( - () => window.CMP !== undefined && !window.CMP.popUpVisible(), + () => !CMP.popUpVisible(), 500 ) + // Optional -- for granular control of initialization if (noConsentNeeded) { ctx.abort({ loadSegmentNormally: true }) } else if (allTrackingDisabled) { ctx.abort({ loadSegmentNormally: false }) } }, + getCategories: () => { - // e.g. { Advertising: true, Functional: false } - return normalizeCategories(window.CMP.consentedCategories()) + const CMP = await getCMP() + return normalizeCategories(CMP.consentedCategories()) // Expected format: { foo: true, bar: false } + }, + + registerOnConsentChanged: (setCategories) => { + const CMP = await getCMP() + CMP.onConsentChanged((event) => { + setCategories(normalizeCategories(event.detail)) + }) }, }) + + +const getCMP = async () => { + await resolveWhen(() => window.CMP !== undefined, 500) + return window.CMP +} ``` ## Wrapper Usage API @@ -36,9 +54,7 @@ import { AnalyticsBrowser } from '@segment/analytics-next' export const analytics = new AnalyticsBrowser() -withCMP(analytics) - -analytics.load({ +withCMP(analytics).load({ writeKey: ' }) @@ -58,9 +74,7 @@ analytics.load({ ```js import { withCMP } from './wrapper' -withCMP(window.analytics) - -window.analytics.load(' }) > - +