Skip to content

Support for Multiple Versions of Analytics.js #7005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

prigiattiperrut
Copy link
Contributor

Proposed changes

Updated documentation to reflect the possibility of running multiple versions of Analytics.js (e.g., a snippet version and an npm version) with different write keys in the same environment.

Merge timing

ASAP once approved

Related issues (optional)

segmentio/analytics-next#1127

https://twilio.slack.com/archives/C9Z93GW76/p1725380202861859

Note that you *cannot* load Analytics.js twice on the same page, even if you're using different write keys. You might encounter `Uncaught RangeError: Maximum call stack size exceeded`. You can conditionally set the write key based on an environment variable.
### Analytics.js Snippet Loaded More Than Once

It is not possible to load the Analytics.js snippet twice on the same page, even if different write keys are used. Doing so often results in errors like `Uncaught RangeError: Maximum call stack size exceeded`. However, you can conditionally set the write key based on an environment variable:
Copy link
Contributor

@silesky silesky Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but it "should" be possible to use two snippets in the same page --just change one snippet to use the another variable name (eg analytics1 and analytics2).

The new snippet makes it super easy to rename the analytics variable to something else.

Worth testing, there were a lot of assumptions built into the library that there would only be one snippet, but we've gradually refactored them out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@forstisabella
Copy link
Contributor

hi @prigiattiperrut and @silesky - any movement on this PR? Should we close this PR?

@forstisabella forstisabella requested a review from silesky June 30, 2025 15:26
silesky
silesky previously approved these changes Jun 30, 2025
@forstisabella forstisabella merged commit 93566d9 into develop Jun 30, 2025
4 checks passed
@forstisabella forstisabella deleted the prigiattiperrut-patch-4 branch June 30, 2025 15:54
Copy link
Contributor

Thank you for your contribution! Your pull request is merged, but may take a day or two to appear on the site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants