Skip to content

Commit 5dcec5b

Browse files
authored
Merge pull request #5949 from segmentio/update_docs_for_snippet_5.2.1
Add docs for installing Analytics under custom global key
2 parents ed0ee57 + 31eee70 commit 5dcec5b

File tree

1 file changed

+11
-0
lines changed
  • src/connections/sources/catalog/libraries/website/javascript

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,17 @@ To minimize client-side data loss, Segment provides a few workarounds. However,
921921
922922
* Consider using one of Segment’s [server-side libraries](/docs/connections/sources/#server). Using a server-side library eliminates concerns about tracking blockers and privacy browsers that can prevent Segment from loading. This option may require additional code to track actions like a Page call, as you now need to manually pass contextual information that would have been automatically collected by Analytics.js, like `url`, `path`, and `referrer`. Note that some destinations are device-mode only.
923923
924+
## Installing the library under a custom global namespace
925+
926+
When you load Analytics.js through snippet code, by default, the SDK installs on `window.analytics` global variable. If this causes a conflict with another library on your page, you can change the global variable used by Analytics.js if you use snippet version 5.2.1 or later.
927+
928+
Change the global variable in the beginning of your snippet code as shown below. In this case, Analytics.js uses `window.custom_key` to load instead of `window.analytics`.
929+
930+
```diff
931+
- !function(){var i="analytics", ...
932+
+ !function(){var i="custom_key", ...
933+
```
934+
924935
## Add destinations from npm
925936
926937
Bundle the destinations you want loaded from [npm](https://www.npmjs.com/package/@segment/analytics-next){:target="_blank"} instead of having them loaded from a remote CDN. This enables you to have fewer network requests when adding destinations.

0 commit comments

Comments
 (0)