Conversation
🦋 Changeset detectedLatest commit: 31dd1d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hey @oscb! Thanks for taking this. I thought the goal was to allow users to use window.foo.track() rather than window.analytics.track()? So the config option would be like 'analyticsGlobalKey', and we save that key in memory -- using it whenever we want to get the global analytics, like how getCDNUrl() works. The fact that this would also be the same reference as the buffer is just an implementation detail. Maybe I'm missing some context? |
Yes, it's sort of the idea. I think the name of the config option can be changed to Per my discussion with Chris we're not yet changing the script part of it as it is going to be a challenge given that the script itself uses |
| '@internal/consent-tools-integration-tests': minor | ||
| --- | ||
|
|
||
| Adds `bufferKey` option for setting custom global window buffers |
There was a problem hiding this comment.
| Adds `bufferKey` option for setting custom global window buffers | |
| Adds `globalAnalyticsKey` option for setting custom global window buffers |
| }) | ||
| }) | ||
|
|
||
| describe('bufferKey', () => { |
There was a problem hiding this comment.
| describe('bufferKey', () => { | |
| describe('globalAnalyticsKey', () => { |
| @@ -0,0 +1,26 @@ | |||
| import { createTaskGroup } from '../task-group' | |||
| */ | ||
| highEntropyValuesClientHints?: HighEntropyHint[] | ||
| /** | ||
| * Key for the global window property storing the buffered calls |
There was a problem hiding this comment.
| * Key for the global window property storing the buffered calls | |
| * When using the snippet, this is the key that points to the global analytics instance (e.g. window.analytics). |
| analytics: Analytics, | ||
| buffer: PreInitMethodCallBuffer | ||
| ): Promise<void> { | ||
| const calls = getGlobalAnalytics() |
There was a problem hiding this comment.
Can we get rid of this now? i.e restore the old function signature of "popSnippetWindowBuffer"?
There was a problem hiding this comment.
Yea I guess we don't ned this anymore since we store it globally
| ;(window as any).analytics = (await AnalyticsBrowser.standalone( | ||
| writeKey, | ||
| options | ||
| )) as AnalyticsSnippet |
There was a problem hiding this comment.
Could we add a setGlobalAnalyticsMethod?
Then we can do:
setGlobalAnalytics(await AnalyticsBrowser.standalone(
writeKey,
options
)))| noConflict(): Analytics { | ||
| console.warn(deprecationWarning) | ||
| window.analytics = _analytics ?? this | ||
| ;(window as any).analytics = _analytics ?? this |
There was a problem hiding this comment.
We probably want to add a setGlobalAnalytics method and do something like:
setGlobalAnalytics(_analytics ?? this)
silesky
left a comment
There was a problem hiding this comment.
Small late breaking feedback just noticed!
| @@ -0,0 +1,31 @@ | |||
| import { AnalyticsSnippet } from './standalone-interface' | |||
There was a problem hiding this comment.
Since file has import side effects -- I think we should name it 'global-analytics-helpers.ts ' or something like that, so nobody puts anything else in it. It could also go in /lib
There was a problem hiding this comment.
Good point. It stopped being only an utils file
|
|
||
| /** | ||
| * Gets the global analytics instance/buffer | ||
| * @param key name of the window property where the buffer is stored (default: analytics) |
There was a problem hiding this comment.
Can we change the comment to say "global analytics/buffer"
| @@ -0,0 +1,6 @@ | |||
| --- | |||
| '@segment/analytics-next': minor | |||
| '@internal/consent-tools-integration-tests': minor | |||
There was a problem hiding this comment.
Oops... this bump looks like a mistake
| @@ -44,7 +44,7 @@ const WebWorker: React.FC = () => { | |||
| }} | |||
| value="Track!" | |||
There was a problem hiding this comment.
It's actually fine to do:
declare global {
interface Window {
analytics: AnalyticsSnippet
}
}
... since this is not a published repo
There was a problem hiding this comment.
I'll leave it as it is for now. But yeah, doesn't matter.
yarn changeset. Read about changesets here).