Skip to content

Commit cbfae45

Browse files
committed
Add docs for snippet 5.2.1
1 parent 4fc2c64 commit cbfae45

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 loading Analytics.js through snippet code, the SDK gets installed on `window.analytics` global variable by default. However, if that causes a conflict with another library on your page, the global variable used by Analytics.js can be changed assuming you are using snippet version 5.2.1 or later.
927+
928+
Simply make this one change in the begining of your snippet code as shown below. In this case, Analytics.js will use `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)