Reputation: 15042
A mobile app tracks events using the Google Analytics iOS SDK.
func recordEvent(_ category: String, action: String, label: String?, value: Int?) {
guard let builder = GAIDictionaryBuilder.createEvent(
withCategory: category,
action: action,
label: label,
value: value as NSNumber?)
else { return }
GAI.sharedInstance().defaultTracker.send(builder.build() as [NSObject: AnyObject])
}
It also tracks system events that occur when the app is launched in background without user interaction. However it seems as if every event that is tracked is considered an Active User
in the Google Analytics Realtime dashboard. So it corrupts the number of users that are currently using the app.
What can I do so that tracked system events are not influencing the number of active users?
Upvotes: 2
Views: 801
Reputation: 2011
I have researched the same question, and what I have found is that setting events to non-interactive affects session duration and bounce rates but has no affect on counting active users or sessions. This blog post from 2014 states this: https://www.lunametrics.com/blog/2014/05/06/noninteraction-events-google-analytics/
My suggested solution is that whenever the app goes to the background, set the tracker userId to a dummy value, such as "backgroundUser":
guard let tracker = GAI.sharedInstance().defaultTracker else { return }
tracker.set(kGAIUserId, value: "backgroundUser")
Then whenever the app returns to the foreground, set the userId back to the actual user's userID.
This will cause all foreground user-initiatated traffic to count for the correct users, and it will properly track the actual number of users actively using the app. All background activity will be attributed to the single dummy user. The session counts will still include all sessions, foreground and background.
Upvotes: 1
Reputation: 1515
To send a non-interaction event to GA using the iOS GA SDK, you would do this:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
// Set non-interaction hit property
[tracker set: kGAINonInteraction
value:@"1"];
// Send event
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Test"
action:@"Test"
label:@"Test"
value:nil] build]];
P.S. I'm not very fluent with ObjectiveC so the syntax above may not be perfect but it should give you some idea.
Upvotes: 0