analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Unloading Plugins based on Path

Open markojak opened this issue 1 year ago • 1 comments

Hi All,

Does anyone know if this wrapper allows for the ability to unload and then load a separate Segment.com writeKey based on the router path? I can't find any documentation on unloading plugins

What we're trying to do is exclude Segment.com from loading marketing (google ads, Bing etc.) on App paths. What makes this hard to do with NextJS is that it will persist the script across marketing/app pages and you cannot do a analytics.load("") update call in analytics.js because segment re-writes these functions (I think)

markojak avatar Mar 29 '24 16:03 markojak

You can conditionally enable/disable stuff https://getanalytics.io/conditional-loading/#enabling--disabling-plugins

routerListenerThingie((route) => {
  if (route === 'foo') {
    analytics.plugins.disable(['segment])
  }
})

Or perhaps you can initialize another analytics instance without those plugins and call that instances .page, .track etc.

DavidWells avatar Apr 05 '24 22:04 DavidWells