End of kGAISessionControl in Swift

I want to use Google Analytics v3.13 in my iOS app in Swift. This is an internet radio receiver. I need to know approximately how many listeners I have in my application.

I am using this code to add an event when the user starts listening (like the play button for clicks):

let tracker = GAI.sharedInstance().defaultTracker
let builder = GAIDictionaryBuilder.createEventWithCategory("shoutcast_events", action: "listening", label: nil, value: nil)
tracker.set(kGAISessionControl, value: "start")
tracker.send(builder.build() as [NSObject : AnyObject])
tracker.set(kGAISessionControl, value: nil)

      

And when the user stops listening (like hitting the stop button), I use this:

let tracker = GAI.sharedInstance().defaultTracker
let builder = GAIDictionaryBuilder.createEventWithCategory("shoutcast_events", action: "listening", label: nil, value: nil)
tracker.set(kGAISessionControl, value: "end")
tracker.send(builder.build() as [NSObject : AnyObject])
tracker.set(kGAISessionControl, value: nil)

      

When I click the play button, the event is added to Google Analytics, but when I click the Stop button, the event is still present. I want it to be removed. The event disappears for about 5 minutes even if I don't press the Stop button.

What am I doing wrong? How to do it? Maybe there is a better solution? :)

+3


source to share





All Articles