Use Google parser in your app

Source: Internet
Author: User

---------------------------------------- -----------------------------------

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.