From c60ce068fb1f1ebe36dd6cd4e09cd0c54d345516 Mon Sep 17 00:00:00 2001 From: prigiattiperrut <47340158+prigiattiperrut@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:55:58 +0100 Subject: [PATCH 1/2] Update troubleshooting.md --- .../website/javascript/troubleshooting.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md index a0364afa82..b5cd94175e 100644 --- a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md @@ -20,9 +20,11 @@ Segment also provides a Chrome web extension, [Segment Inspector](/docs/connecti Solution: [Follow the Analytics.js Quickstart Guide](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/) -## Are you loading two instances of Analytics.js? +## Loading Multiple Instances of Analytics.js -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: Example: ```js @@ -30,6 +32,14 @@ var writeKey; ENV === 'production' ? writeKey = 'A' : writeKey = 'B'; ``` +### Multiple Versions of Analytics.js + +It is possible to load multiple versions of Analytics.js, such as a snippet version and an npm version (with different writekeys), in the same environment without them interfering with each other. This allows the npm library and the browser snippet to coexist without conflicting.Just keep in mind the following limitations with this approach: + +**1. Device-Mode Destination Conflicts**: If you are using the same device-mode destination in both instances (i.e., across different writekeys), conflicts may occur. This is due to third-party scripts that don't support global instances. To avoid issues, ensure you are not using the same device-mode destination between different write keys. + +**2. CDN URL Customization:** We currently do not support overriding the CDNURL when using multiple instances of Analytics.js. + ## Do you see events appear in your debugger? When you reload the page, does your debugger show a new [`page`](/docs/connections/spec/page)? You can also check the JavaScript console in the browser and manually fire an event, like an Identify call, which would show up in the debugger. From e1cd04b8e145847678b183da1933a80fa10112b6 Mon Sep 17 00:00:00 2001 From: forstisabella <92472883+forstisabella@users.noreply.github.com> Date: Mon, 30 Jun 2025 11:26:24 -0400 Subject: [PATCH 2/2] Apply suggestions from code review --- .../website/javascript/troubleshooting.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md index b5cd94175e..ab85dcbb30 100644 --- a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md @@ -20,11 +20,13 @@ Segment also provides a Chrome web extension, [Segment Inspector](/docs/connecti Solution: [Follow the Analytics.js Quickstart Guide](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/) -## Loading Multiple Instances of Analytics.js +## Loading multiple instances of Analytics.js -### Analytics.js Snippet Loaded More Than Once +### 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: +You cannot load the Analytics.js snippet twice on the same page, even if different write keys are used. Doing so might result in errors like `Uncaught RangeError: Maximum call stack size exceeded`. + +However, you can conditionally set the write key based on an environment variable: Example: ```js @@ -34,11 +36,12 @@ ENV === 'production' ? writeKey = 'A' : writeKey = 'B'; ### Multiple Versions of Analytics.js -It is possible to load multiple versions of Analytics.js, such as a snippet version and an npm version (with different writekeys), in the same environment without them interfering with each other. This allows the npm library and the browser snippet to coexist without conflicting.Just keep in mind the following limitations with this approach: +You can load multiple versions of Analytics.js in the same environment. For example, you could have both a snippet version and an npm version on one page, each with different write keys. This allows the npm library and the browser snippet to coexist without conflicting. -**1. Device-Mode Destination Conflicts**: If you are using the same device-mode destination in both instances (i.e., across different writekeys), conflicts may occur. This is due to third-party scripts that don't support global instances. To avoid issues, ensure you are not using the same device-mode destination between different write keys. +Keep the following limitations in mind: -**2. CDN URL Customization:** We currently do not support overriding the CDNURL when using multiple instances of Analytics.js. +- **Device-Mode Destination Conflicts**: If you are using the same device-mode destination in both instances (for example, across different write keys), conflicts may occur. This is due to third-party scripts that don't support global instances. To avoid issues, ensure you are not using the same device-mode destination with different write keys. +- **CDN URL Customization:** Segment does not support overriding the CDNURL when using multiple instances of Analytics.js. ## Do you see events appear in your debugger?