4
votes

I've implemented the GA in my code as it's shown in https://developers.google.com/analytics/devguides/collection/ios/devguide.

I start the GA tracker with: [[GANTracker sharedTracker] startTrackerWithAccountID:gaAccountId dispatchPeriod:kDispatchPeriodSeconds delegate:self];

The GA Profile is specified for Mobile Apps and I'm using Google Analytics SDK for iOS v1 (Legacy)

The problem is that real time feature doesn't work. It's always says that there is 0 visitors. Do you have any suggestions what could be the problem.

5

5 Answers

2
votes

You have to add trackPageView to the views you wish to track.

2
votes

In the current (2.0) sdk you should use sendView instead of trackPageView: [[[GAI sharedInstance] defaultTracker] sendView:@"my_view"];

Or you could use the already mentioned GAITrackedViewController.

But I noticed that the Realtime feature just doesn't always work, I sometimes experienced that completely deleting an account and/or creating a new one sometimes resolves this issue. Also it can just be busy on the server side, so it might just be working already but delayed.

Sometimes I test with a working account to find out wether the error is on me or not.

2
votes

In the AppDElegate.m file :

#import "AppDelegate.h"
#import "GAI.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   [GAI sharedInstance].trackUncaughtExceptions  = YES;

   [GAI sharedInstance].dispatchInterval = 1;

   [[[GAI sharedInstance] logger]setLogLevel:kGAILogLevelVerbose];

   id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"TrackingId"];

   [GAI sharedInstance].defaultTracker = tracker;

   return YES;
}

In ViewController.h

#import <UIKit/UIKit.h>
#import "GAITrackedViewController.h"

@interface FirstViewController : GAITrackedViewController


@end

In ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    self.screenName = @"RED Screen";
}

Try it. This worked for me just fine. I tried it more than three apps. And All are working for realtime. If your account for your app is new then you might have to wait for 24h or more to see the result. Sometimes it take time to display realtime data without any reason.

1
votes

Follow this steps you will get the real time result

  1. in Appdelegate write setdespatchinterval

[GAI sharedInstance].dispatchInterval = 20;

2.add track pageview like this.

Extend your view controller from GAITrackedViewController

'@interface ActivityViewController : GAITrackedViewController          @end'

implement the viewdidload method of your viewcontroller

-(void)viewDidAppear:(BOOL)animated{

 self.screenName = @"Home Screen";

}

for how google analytics works you can visit this link

https://www.e-nor.com/blog/google-analytics/mobile-analytics-real-time-reporting-not-what-youd-expect

Hope this will help someone.

0
votes

If you sure about getting data but real time, then please change your time interval to 1. That fixed for me.

    // Optional: configure GAI options.
    GAI *gai = [GAI sharedInstance];
    gai.dispatchInterval = 1;
    gai.trackUncaughtExceptions = YES;  // report uncaught exceptions
    #ifdef DEBUG
        gai.logger.logLevel = kGAILogLevelVerbose;  // remove before app releaseAppDelegate.m
    #endif