Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/analytics-plugin-segment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const analytics = Analytics({
plugins: [
segmentPlugin({
writeKey: '123-xyz'
loadOptions: { disableClientPersistence: true }
})
]
})
Expand All @@ -118,6 +119,7 @@ const analytics = Analytics({
| `disableAnonymousTraffic` <br/>_optional_ - boolean| Disable loading segment for anonymous visitors |
| `customScriptSrc` <br/>_optional_ - boolean| Override the Segment snippet url, for loading via custom CDN proxy |
| `integrations` <br/>_optional_ - object| Enable/disable segment destinations https://bit.ly/38nRBj3 |
| `loadOptions` <br/>_optional_ - object| Options object passed as the second argument to `analytics.load(writeKey, loadOptions)`. Allows customisation of Segment loading. |

## Server-side usage

Expand Down
10 changes: 7 additions & 3 deletions packages/analytics-plugin-segment/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const config = {
/* Your segment writeKey */
writeKey: null,
/* Options to pass in the load function call */
loadOptions: {},
/* Disable anonymous MTU */
disableAnonymousTraffic: false,
/* Sync segment Anonymous id with `analytics` Anon id */
Expand All @@ -18,14 +20,16 @@ const config = {
* @link https://segment.com/docs/sources/website/analytics.js/
* @param {object} pluginConfig - Plugin settings
* @param {string} pluginConfig.writeKey - Your segment writeKey
* @param {object} [pluginConfig.loadOptions] - Options to pass in the segment load call
* @param {boolean} [pluginConfig.disableAnonymousTraffic] - Disable loading segment for anonymous visitors
* @param {boolean} [pluginConfig.customScriptSrc] - Override the Segment snippet url, for loading via custom CDN proxy
* @param {object} [pluginConfig.integrations] - Enable/disable segment destinations https://bit.ly/38nRBj3
* @return {object} Analytics plugin
* @example
*
* segmentPlugin({
* writeKey: '123-xyz'
* writeKey: '123-xyz',
* loadOptions: { disableClientPersistence: true }
* })
*/
function segmentPlugin(pluginConfig = {}) {
Expand Down Expand Up @@ -127,7 +131,7 @@ function segmentPlugin(pluginConfig = {}) {
}

function initialize({ config, instance }) {
const { disableAnonymousTraffic, writeKey, customScriptSrc } = config
const { disableAnonymousTraffic, writeKey, loadOptions, customScriptSrc } = config
if (!writeKey) {
throw new Error('No segment writeKey')
}
Expand Down Expand Up @@ -177,7 +181,7 @@ function initialize({ config, instance }) {
analytics._loadOptions = e
};
analytics.SNIPPET_VERSION = "4.1.0";
analytics.load(writeKey);
analytics.load(writeKey, loadOptions);
}
}
}();
Expand Down