如何在iphone app中加入google跟踪代码

1.登录google分析网站( http://google.com/analytics)添加一个新的Website Profile,截图如下:
  

  可参考网站:http://www.icodeblog.com/2010/04/22/how-to-integrate-google-analytics-tracking-into-your-apps-in-7-minutes/

2.在http://code.google.com/intl/zh-CN/mobile/analytics/docs/iphone/中下载ios 的google跟踪SDK
  在工程中导入

3.在工程的delegate文件的 applicationDidFinishLaunching方法中,加入代码:
  
#import "GANTracker.h"
[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-15609865-3"
                                dispatchPeriod:10
                                delegate:nil];
   
startTrackerWithAccountID:google申请账号里面的那个webprofile文件的唯一标示
  dispatchPeriod :表示多少秒之后用户的行为数据传给google
4. 页面跟踪
NSError *error;

if
(![[GANTracker sharedTracker] trackPageview:@"/app_launched" withError:&error]) { // Handle error here }
上述代码可以加在你代码中的任何位置,比如initwithFrame等初始化方法中,不过得包含头文件
#import "GANTracker.h"

5.事件跟踪:
  

- (IBAction) saveTheWorld:(id) sender
{

NSError *error; if (![[GANTracker sharedTracker] trackEvent:@"button_click" action:@"save_the_world" label:@"my_label" value:-1 withError:&error]) { // Handle error here } }

参考网站:
     http://www.icodeblog.com/2010/04/22/how-to-integrate-google-analytics-tracking-into-your-apps-in-7-minutes/
    http://code.google.com/intl/zh-CN/mobile/analytics/docs/iphone/


原文地址:https://www.cnblogs.com/cnsec/p/11515917.html