---------------------------------------- -----------------------------------
Tracks network phones, mobile websites, and mobile apps.
In this tutorial, you can learn how to use Google parser in your app.
---------------------------------------- -----------------------------------
Open xcode and select 'empty application' to create a new project.
Create a file based on 'uiviewcontroller subclass. Name the new class ('googleanalyticsviewcontroller' is used) and select a subclass of uiviewcontroller.
Open the file: appdelegate. M and import the header files: "googleanalyticsviewcontroller. H" and "gantracker. H", as shown below:
#import "GoogleAnalyticsViewController.h"#import "GANTracker.h"
In method name: Application: didfinishlaunchingwitexceptions: write some code.
Create a 'googleanalyticsviewcontroller' and use 'googleanalyticsviewcontroller' as the root view to create a uinavigationcontroller.
Now we need to add a sub-view for uiwindow: uinavigationcontroller.
Then we can install Google Analytics gantracker to get the key. Do the following.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; GoogleAnalyticsViewController *googleAnalyticsViewController = [[GoogleAnalyticsViewController alloc] initWithNibName:@"GoogleAnalyticsViewController" bundle:[NSBundle mainBundle]]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:googleAnalyticsViewController]; [[self window] addSubview:[nav view]]; // Create GANTracker [[GANTracker sharedTracker] startTrackerWithAccountID:@"your-own-account-id" dispatchPeriod:60 delegate:nil]; [self.window makeKeyAndVisible]; return YES;}
Download the compressed 'Google analytics library 'from the attachment and decompress the compressed file. Right-click your project file and choose add and unzip file. Check: Copy items into destination group's folder (if needed), and then click Finish.
Open your 'googleanalyticsviewcontroller. XIB 'and add a button.
Open this 'auxiliary editing tool '. Add an attribute to the added object and name it (googlebutton is used). You can press Ctrl-to click an object, and drag it to the 'auxiliary editing tool' on the left to create this attribute.
Return to the standard operation interface.
Write some code in viewdidload: In your 'googleanalyticsviewcontroller. M. Use a Google parser to track a page.
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSError *error; if (![[GANTracker sharedTracker] trackPageview:[article articleURL] withError:&error]) { NSLog(@"error in trackPageview"); }}
Do the above before adding a method. We also need to define the googlebuttontouchupinside method: add it to the code bar to track an event.
- (IBAction)GoogleButtonTouchUpInside:(id)sender { NSError *error; if (![[GANTracker sharedTracker] trackEvent:@"Button" action:@"Start google search" label:@"label" value:99 withError:&error]) { NSLog(@"error in trackEvent"); }}
Now you have used Google parser in your app. You can complete the simple code in your existing app.
Translation is a little stiff. Please forgive me.
From: http://www.altinkonline.nl/tutorials/xcode/google-analytics/google-analytics-in-xcode/