-
Notifications
You must be signed in to change notification settings - Fork 141
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 analytics key (#928)
- Loading branch information
Showing
18 changed files
with
210 additions
and
50 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 | ||
'@segment/analytics-core': minor | ||
--- | ||
|
||
Adds `globalAnalyticsKey` 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
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
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
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,31 @@ | ||
import { AnalyticsSnippet } from '../browser/standalone-interface' | ||
|
||
/** | ||
* Stores the global window analytics key | ||
*/ | ||
let _globalAnalyticsKey = 'analytics' | ||
|
||
/** | ||
* Gets the global analytics/buffer | ||
* @param key name of the window property where the buffer is stored (default: analytics) | ||
* @returns AnalyticsSnippet | ||
*/ | ||
export function getGlobalAnalytics(): AnalyticsSnippet | undefined { | ||
return (window as any)[_globalAnalyticsKey] | ||
} | ||
|
||
/** | ||
* Replaces the global window key for the analytics/buffer object | ||
* @param key key name | ||
*/ | ||
export function setGlobalAnalyticsKey(key: string) { | ||
_globalAnalyticsKey = key | ||
} | ||
|
||
/** | ||
* Sets the global analytics object | ||
* @param analytics analytics snippet | ||
*/ | ||
export function setGlobalAnalytics(analytics: AnalyticsSnippet): void { | ||
;(window as any)[_globalAnalyticsKey] = analytics | ||
} |
Oops, something went wrong.