Dynamically turn off activity tracking

I have a situation where I have two trackers in my application and I need to be able to use activity tracking for one tracker in certain scenarios, but not in others.

Is there any way I can dynamically turn off activity tracking after it has been passed to the client on initialization?

Hello, welcome to the forums!

What tracker are you using - what kind of app is it?

Hi there, thank you. I’m using the browser tracker in a React app.

"@snowplow/browser-tracker": "^3.3.1",

Does this docs page about multiple trackers help?

As far as I’m aware it’s not possible to pause the browser tracker, this feature is only present in our mobile trackers for iOS/Android/React Native.

It’s not terribly easy to tell from the docs, but I found this API definition in the repo, which clarifies that you can pass a list of tracker names to enableActivityTracking the same way you can for the track methods.

// @public
export function enableActivityTracking(configuration: ActivityTrackingConfiguration, trackers?: Array<string>): void;

If you pass the array, only the tracker names in the array will have activity tracking enabled. Hope that helps. :slight_smile:

(Edit: I started writing, got sidetracked, and Miranda had already beaten me to it by the time I pressed post :sloth: )

Hmm, ok thanks for the feedback everyone. Not sure I can exactly do what I want in this instance since I want to have activity tracking on for both trackers at a certain point but turn it off at another. Thanks anyways :slight_smile:

Hi everybody,
we run into a similar issue on a single page application. We want to enable activity tracking just on certain pages / sub directories. Since there is no disableActivityTracking function, we need to build a cumbersome workaround.
Maybe the reason is not so obvious: but on SPAs you need to initialize the tracker only once. If the first tracker initialization (initial page load) happens on a page where ActivityTracking should be enabled, it will be enabled on all subsequent pages.

bottom line: In my opinion, there should be a disableActivityTracking function.

To clarify this behaviour - when you disable activity tracking and then enable it again, should it resume from where it previous left off or reset entirely and start counting again from 0?

Either way I’ve created a Github issue for this for us to look into - Add disableActivityTracking function · Issue #1161 · snowplow/snowplow-javascript-tracker · GitHub

1 Like

Thanks Mike, sounds good. Maybe I am missing something, but I think it should be reset entirely and start counting again from 0…looking forward to it :innocent: