0

I am trying to get Google Analytics working with my application.

I have

Integrated the official Google Analytics SDK 3 to my project

AppDelegate.m

// Initialize the default tracker. After initialization, [GAI sharedInstance].defaultTracker
// returns this same tracker.
// TODO: Replace the tracker-id with your app one from https://www.google.com/analytics/web/
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"XX-XXXXX-X"];

// Provide unhandled exceptions reports.
[GAI sharedInstance].trackUncaughtExceptions = YES;

// Enable Remarketing, Demographics & Interests reports. Requires the libAdIdAccess library
// and the AdSupport framework.
// https://developers.google.com/analytics/devguides/collection/ios/display-features
tracker.allowIDFACollection = YES;

Then in WordPressViewController.m

    - (void) viewDidLoad
{

    [super viewDidLoad];
   id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        @"appview", kGAIHitType, @"Home Screen", kGAIScreenName, nil];
[tracker send:params];

Also bitcode is not working with the latest sdk somehow (don´t know if this is important to work for the tracker)

However when I run the app go to the screen, real time data doesn´t show anything.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • ref this link may be helps you https://developers.google.com/analytics/devguides/collection/ios/v3/ – Anbu.Karthik Oct 19 '15 at 10:41
  • How long ago did you create the Google Analyitcs account. It can take 48 - 72 hours for it to start showing data. Yes real-time as well. – Linda Lawton - DaImTo Oct 19 '15 at 11:04
  • bitcode is not needed to work for any app, this helps iOS App store for app thinning but google seems to have not enabled it right now, you need to set EnableBitCode flag to No in your buildsettings. – pk75 Oct 19 '15 at 11:11
  • Account for this Tracking ID is 2-3 weeks old. Thanks for the feedback on bitcode – Wilfried Mueller Oct 19 '15 at 14:10

3 Answers3

0

Set up in appDelegate in didFinishLaunchingWithOptions method.

[[GAI sharedInstance] setDispatchInterval:kGaDispatchPeriod]; // set your period .

[[GAI sharedInstance] setOptOut:NO];

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

[[GAI sharedInstance] setTrackUncaughtExceptions:YES];

id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:kGaPropertyId]; //// Placeholder property ID.

[tracker setAllowIDFACollection:NO];

make property of GAITracker in appDelegate

@property (strong, nonatomic) id<GAITracker> tracker;

And set up in view conroller in viewDidAppear ..

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:NSStringFromClass([self class])];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];

Hope it help you.

Garry
  • 407
  • 2
  • 15
0

Real time data finally working.

Changed

[GAI sharedInstance].dispatchInterval = 20;

to

[GAI sharedInstance].dispatchInterval = 1;

0

I am a Google SME (Subject Matter Expert) at a Mobile Development company and have had the pleasure of subjecting myself to many headaches trying to ensure we had our implementation correct.

With that said, the reason you didn't see any data reporting to Real Time analytics with a dispatch interval set to 20 is because that means your data is batch-reporting every 20 minutes; this is too long of a time window to show up in the real-time data which is limited to 60 seconds on the smaller view and 30 minutes on the larger view.

With that said, the dispatched data does not appear in the real-time data at the time it was dispatched. Instead, the table will merely reflect when an event/screen view took place - there is no indication when the data got dispatched.

Theoretically, you could wait 20 minutes on the original setting and, assuming you configured everything correctly, you would see at least some of the data show up near the end of the larger time-window for real-time events, but much of the activity would be "missing" simply because it took place longer than 30 minutes ago.

To really test this, try doing the following (instant dispatching): Set the dispatch interval to 0 - this will trigger events and screens to be reported immediately. YOU SHOULD ONLY DO THIS FOR DEBUGGING PURPOSES, OR IF YOU HAVE A NEED FOR INSTANT DISPATCHING (Google docs don't recommend instant dispatching since it drains battery life much faster)

Keep in mind that "real-time" data will only show up several seconds after the last dispatch call. Some unofficial resources I have found claimed that it can take up to a minute after the last dispatch, so patience is key here.