-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom global buffer key
- Loading branch information
Showing
13 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@segment/analytics-next': minor | ||
'@internal/consent-tools-integration-tests': minor | ||
--- | ||
|
||
Adds `bufferKey` option for setting custom global window buffers |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Analytics, InitOptions } from '../core/analytics' | ||
|
||
export interface AnalyticsSnippet extends AnalyticsStandalone { | ||
load: (writeKey: string, options?: InitOptions) => void | ||
} | ||
|
||
export interface AnalyticsStandalone extends Analytics { | ||
_loadOptions?: InitOptions | ||
_writeKey?: string | ||
_cdn?: string | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AnalyticsSnippet } from './standalone-interface' | ||
|
||
/** | ||
* Gets the global analytics instance/buffer | ||
* @param key name of the window property where the buffer is stored (default: analytics) | ||
* @returns AnalyticsSnippet | ||
*/ | ||
export function getGlobalAnalytics( | ||
key = 'analytics' | ||
): AnalyticsSnippet | undefined { | ||
return (window as any)[key] | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
8 changes: 5 additions & 3 deletions
8
packages/consent/consent-tools-integration-tests/src/page-bundles/snippet/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import { AnyAnalytics } from '@segment/analytics-consent-tools' | ||
import { oneTrust } from '@segment/analytics-consent-wrapper-onetrust' | ||
import { getGlobalAnalytics } from '@segment/analytics-next' | ||
|
||
oneTrust(window.analytics, { | ||
oneTrust(getGlobalAnalytics() as AnyAnalytics, { | ||
integrationCategoryMappings: { | ||
Fullstory: ['C0001'], | ||
'Actions Amplitude': ['C0004'], | ||
}, | ||
}) | ||
|
||
window.analytics.load('9lSrez3BlfLAJ7NOChrqWtILiATiycoc') | ||
window.analytics.track('Hello from the snippet') | ||
getGlobalAnalytics()?.load('9lSrez3BlfLAJ7NOChrqWtILiATiycoc') | ||
getGlobalAnalytics()?.track('Hello from the snippet') |