Skip to content

Commit 93566d9

Browse files
Merge pull request #7005 from segmentio/prigiattiperrut-patch-4
Support for Multiple Versions of Analytics.js
2 parents 94f32be + 67aaea1 commit 93566d9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,30 @@ Segment also provides a Chrome web extension, [Segment Inspector](/docs/connecti
2222

2323
To learn more, follow the [Analytics.js Quickstart Guide](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/).
2424

25-
## Are you loading two instances of Analytics.js?
25+
## Loading multiple instances of Analytics.js
2626

27-
Note that you *cannot* load Analytics.js twice on the same page, even if you're using different write keys. If you do, you might encounter `Uncaught RangeError: Maximum call stack size exceeded`. Instead, you can conditionally set the write key based on an environment variable.
27+
28+
### Analytics.js snippet loaded more than once
29+
30+
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`.
31+
32+
However, you can conditionally set the write key based on an environment variable:
2833

2934
Example:
3035
```js
3136
var writeKey;
3237
ENV === 'production' ? writeKey = 'A' : writeKey = 'B';
3338
```
3439

40+
### Multiple Versions of Analytics.js
41+
42+
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.
43+
44+
Keep the following limitations in mind:
45+
46+
- **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.
47+
- **CDN URL Customization:** Segment does not support overriding the CDNURL when using multiple instances of Analytics.js.
48+
3549
## How do I resolve the 'Failed to Load Analytics.js ChunkLoadError'?
3650

3751
The error can occur for different reasons:
@@ -44,6 +58,7 @@ The error can occur for different reasons:
4458

4559
- Cloudflare caching: If you use Cloudflare to proxy Segment, disable caching for the Segment JS file.
4660

61+
4762
## Do you see events appear in your debugger?
4863

4964
When you reload the page, does your debugger show a new [Page call](/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.

0 commit comments

Comments
 (0)