loadPlugin is not implemented?
I'm trying to disable segment anonymous tracking as detailed in the docs here: https://getanalytics.io/plugins/segment/#browser-api
However, it seems that instance.loadPlugin does not exist as called here:
https://github.com/DavidWells/analytics/blob/50152c03d144bd51fbe95e0b44de3cb6764d05b3/packages/analytics-plugin-segment/src/browser.js#L51-L61
So I looked a bit into this and loadPlugin was removed in 19cce0371a9b78e5f1e5b0060915bc8c4b7bb98f
This has obviously broken the disableAnonymousTraffic functionality in the @analytics/segment plugin.
Did you have a plan to reintroduce loadPlugin? What was the reason that you removed it? I can potentially create a PR if you can help me understand the challenges here.
Alternatively, is there a half-way solution for this plugin? Such as just returning from page, track etc if disableAnonymousTraffic === true and instance.user('userId') === undefined?
Bump
One solution could be to have the segment plugin disabled until you check that then call instance.enablePlugin('segment') or instance.plugins.enable('segment').
The enablePlugin event does kick off initializeStart so, in theory, I think it would accomplish the same goal. You would have a ghost dependency that might want to explicitly check for the existence of the segment plugin first via instance.plugins.
If you want to be extra fancy technically you can dispatch a custom event via type property so in a custom plugin you could handle enabling and disabling via that event.
instance.dispatch({ type: [custom event], ...otherProps }); The other props come through in the payload. If that is trouble, use the _ key and place your data there.
Did you try any of the above @deevus ?
I did try using enablePlugin. However in the case of disableAnonymousTraffic, what you want is that the identify call is delivered to Segment once the user has identified, along with any other tracking events that have been previously dispatched.
Only new events are sent to plugins after they are enabled.
I also found that it wasn't deterministic. So if you for example call enablePlugin in identifyStart, you can't guarantee that the plugin will be enabled by the time identify is called.
Okay, interesting, noticed that the behavior was a little strange with the start and end postfixes as well.
Could you perhaps utilize a custom event that is dispatched by the identify event within the segment plugin that handles sending the required data to segment? enablePlugin does return a promise so you could utilize a promise chain returned by that custom event handler or would that still not work?
P.S. I don't use segment so I can talk only to the analytics lib side of things.
Fixed and pushed with @analytics/[email protected]
Sorry for delay. Load plugin was not implemented yet 😃