2

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.

enter image description here

What can I do so that tracked system events are not influencing the number of active users?

Manuel
  • 14,274
  • 6
  • 57
  • 130
  • Have you tried passing in the `&ni` parameter for [non interacting activities](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ni) – Matt Jul 30 '17 at 14:31
  • That parameter doesn't seem to exist for the iOS SDK. – Manuel Jul 30 '17 at 17:35
  • You should be able to set the `&ni` like this: https://developers.google.com/analytics/devguides/collection/ios/v3/advanced#ampersand – faridghar Jul 31 '17 at 03:52
  • @faridghar I read the docs and still don't know how to do it - do you know how? – Manuel Jul 31 '17 at 21:33

2 Answers2

1

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.

Paul King
  • 1,881
  • 20
  • 23
0

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.

faridghar
  • 1,445
  • 2
  • 13
  • 25