知了博客

集天地之精华,吸日月之灵气

« ios控件: UINavigationBar产品需求背后的用户动机 »

在ios上使用Google analytics

在ios上使用Google analytics,今天简单地测试了一下,总结:

Google analytics使用分为普通web(移动web),及app(包括移动app).ios app访问记录,需要几个库:
(libGoogleAnalytics.a,CFNetwork,libsqlite3.0.dylib)
下面是谷歌官网提供的操作步骤:
1。 Open Xcode and create a new iPhone OS project.
2。 Drag GANTracker.h and libGoogleAnalytics.a from the SDK's Library directory into your new project.
3。 Include the CFNetwork framework in your project and link against libsqlite3.0.dylib.
测试结果:
title
以及经测试过的源码:

//
//  ViewController.h
//  anyltics
//
//  Created by sunkey on 12-8-21.
//  Copyright (c) 2012年 sunkey. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end


#import "ViewController.h"
#import "GANTracker.h"

static NSString* const kAnalyticsAccountId = @"UA-xxxxxxxx-1";
static const NSInteger kGANDispatchPeriodSec = 10;
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
    
    
    [[GANTracker sharedTracker] startTrackerWithAccountID:kAnalyticsAccountId
                                           dispatchPeriod:kGANDispatchPeriodSec
                                                 delegate:nil];
    NSError *error;
    
    if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1
                                                         name:@"iOS1"
                                                        value:@"iv1"
                                                    withError:&error]) {
        NSLog(@"error in setCustomVariableAtIndex");
    }
    
    if (![[GANTracker sharedTracker] trackEvent:@"Application iOS"
                                         action:@"Launch iOS"
                                          label:@"Example iOS"
                                          value:99
                                      withError:&error]) {
        NSLog(@"error in trackEvent");
    }
    
    if (![[GANTracker sharedTracker] trackPageview:@"/app_entry_point"
                                         withError:&error]) {
        NSLog(@"error in trackPageview");
    }

    
    NSLog(@"load\n");
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    NSLog(@"unload \n");
    //[[GANTracker sharedTracker] stopTracker];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

@end


参考:Google Analytics SDK for iOS

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Arwen Build 90619 Code detection by Codefense  theme by BokeZhuti

Copyright know blog. Some Rights Reserved.站长(msn):webmaster#webgou.info(#换成@) 粤ICP备09183716号