3

I'd integrated Google analytics in my app. It is working fine for few screens but not for few other screens(ie, viewcontrollers).

Totally I have 45 screens, but the GAI works only for 19 screens. I'd followed the steps in this documentation.

I'd changed as below in all viewcontrollers,

@interface Myviewcontroller : GAITrackedViewController

and imported GAITrackedViewController in both .h and .m files

#import "GAITrackedViewController.h"

It's working fine for some screens but not for some other screens. I'm sending the screen names by using self.screenName = @"Home screen";.

NSLogger is as below for the viewcontrollers that successfully integrated,

VERBOSE: GoogleAnalytics 3.01 -[GAIBatchingDispatcher persist:] (GAIBatchingDispatcher.m:414): Saved hit: {
parameters =     {
    "&_u" = ".etno";
    "&_v" = "mi3.0.1";
    "&an" = My Project;
    "&av" = "1.0";
    "&cd" = "Home Screen";
    "&cid" = "XXXXXXXXXXXXXXXXXXXXXXX";
    "&sr" = 320x480;
    "&t" = appview;
    "&tid" = "UA-XXXXXXX-2";
    "&ul" = en;
    "&v" = 1;
    "&z" = XXXXXXXXXXXXX;
    gaiVersion = "3.01";
    };
    timestamp = "2014-04-28 09:44:17 +0000";
}

But there is no logging for unsuccessfull attempts, after sometime I can see some logging like,

INFO: GoogleAnalytics 3.01 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 0X000007
INFO: GoogleAnalytics 3.01 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 0X000002
INFO: GoogleAnalytics 3.01 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 00000000

I'd checked with all the viewcontrollers, there is no difference in code while integrating Google-Analytics between those screens.

What am I missing? Any Suggestions would be appreciated.

Nazik
  • 8,393
  • 26
  • 72
  • 115

2 Answers2

2

where did you add self.screenName = @"Home screen"; ?

I used to send the page view event instead of using automatic tracking:

//Init once
[GAI sharedInstance].dispatchInterval = 30;
[GAI sharedInstance].trackUncaughtExceptions = NO;
self.tracker = [[GAI sharedInstance] trackerWithTrackingId:gai_id];

And in a common UIViewController class (you can then inherit from this class whenever you want to track the page):

  1. Define a property screenName in .h

    @property(nonatomic, copy) NSString *screenName;

  2. Use it in .m

    -(void)viewDidAppear:(BOOL)animated{ //Google track [super viewDidAppear:animated];

    @try {
        [tracker set:kGAIScreenName value:screenName];
        [tracker send:[[GAIDictionaryBuilder createAppView] build]];
    }
    @catch (NSException *exception) {
        NSLog(@"[ERROR] in Automatic screen tracking: %@", exception.description);
    }
    

    }

  3. Remember to set in inherit ViewControllers

    -(void)viewDidAppear:(BOOL)animated {
      self.screenName = @"my page name";
     [super viewDidAppear:animated];
    }
    

Hope this helps.

Nazik
  • 8,393
  • 26
  • 72
  • 115
Eva Madrazo
  • 4,723
  • 2
  • 19
  • 31
  • I can't understand what you are saying. I'm following the steps in this [documentation](https://developers.google.com/analytics/devguides/collection/ios/v3/). There I can't find a word `kGAIScreenName`. – Nazik Apr 28 '14 at 11:20
  • Hi, in GA 3.0 you can find the information in GAIDictionaryBuilder.h. It says:/*! Returns a GAIDictionaryBuilder object with parameters specific to an appview hit. Note that using this method will not set the screen name for followon hits. To do that you need to call set:kGAIDescription value: on the GAITracker instance. */ + (GAIDictionaryBuilder *)createAppView; – Eva Madrazo Apr 28 '14 at 11:28
  • I got your point +1, need to wait for one day for checking. Thankx. – Nazik Apr 28 '14 at 12:13
1

Eva Madrazo's answer gave me an idea that I went to the GAI tutorial link and there I found an another link for migration guide.

There I found that,

I need to replace,

self.screenName = @"Home screen";

with

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Home Screen"];
[tracker send:[[GAIDictionaryBuilder createAppView]  build]];

Now all the screens receiving hits in the Google Analytics.
But, I need to import

#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"

to avoid undeclared identifier error.

Community
  • 1
  • 1
Nazik
  • 8,393
  • 26
  • 72
  • 115