Google Analytics for iOS track to multiple account

2019-04-24 02:58发布

问题:

I have two different web property id from two different accounts, say UA-1111-11, UA-2222-22 Now, in my iOS app, I need to log to both of them in the events. Is this even possible? If not, is there any workaround?

Here is my high level scenario: I have an existing app where I use google analytics UA-1111-11 to track. Now, I had an agreement with company X (they have UA-2222-22). They told me that I need to send analytics tracking events to their account (UA-2222-22) from my app (and I want to keep UA-1111-11 for my own use).

回答1:

Google is working on their v2 SDK for iOS and Android, and they added a feature for multiple trackers in the same application. Currently, you can download Google Analytics v2 beta 3 for iOS, and start playing with it.



回答2:

Check Google Analytics SDK

Sample code:

#import "RootViewController.h"
#import "GAI.h"

@interface RootViewController ()

@end

@implementation RootViewController
{
- (void)viewDidLoad {
  [super viewDidLoad];

  // Send a screen view to the first property.
  id tracker1 = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Y"];
  [tracker1 sendView:@"/HomeScreen"];

  // Send another screen view to the second property.
  id tracker2 = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Z"];
  [tracker2 sendView:@"Home"];
}

@end

Keep in mind that automated measurement features, like automatic screen and uncaught exception measurement, will only use one tracker to send data to Google Analytics. If you are using these features and want to send data using other trackers, you will need to do so manually.