CẬP NHẬT - Google Analytics SDK dành cho iOS v3
Vì vậy, tôi đang sử dụng v3, và không có bất kỳ sự cố nào:
Tôi đã triển khai nó trong AppDelegate. Trong file .h:
#import "GAI.h"
@property (nonatomic,assign) id<GAITracker> tracker; // I'm not using ARC (assign)
.m:
#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"
// GOOGLE ANALYTICS
[GAI sharedInstance].trackUncaughtExceptions = YES;
[GAI sharedInstance].dispatchInterval = 0;
tracker = [[GAI sharedInstance] trackerWithTrackingId:@"yourGAID"];
Và viết một phương pháp như thế này:
- (void) sendGoogleAnalyticsView:(NSString*)viewName{
[tracker set:kGAIScreenName value:viewName];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
[[GAI sharedInstance] dispatch]; // this will force track your views.
}
Cũ câu trả lời:
Xem câu trả lời dưới đây liên kết này, nếu bạn làm điều đó giống như tôi đã nói trong câu trả lời này, nó phải làm việc
Another stack-overflow answered question about google-analytics
và sử dụng các phương pháp:
[GAI sharedInstance].optOut = YES;
[GAI sharedInstance].dispatchInterval = 0;
[GAI sharedInstance].trackUncaughtExceptions = YES;
tracker = [[GAI sharedInstance] trackerWithTrackingId:@"YOUR TRACKERID"];
[tracker sendView:@"Your View name"];
[tracker sendEventWithCategory:@"YOUR CATEGORY" withAction:@"YOUR ACTION" withLabel:nil withValue:nil];
Tải GoogleAnalyticsiOS_2.0beta4.zip từ this link này sẽ chứa những lớp học những gì bạn cần, và nó sẽ làm việc một cách hoàn hảo. Hãy cẩn thận, google analytics có thời gian chính, để hiển thị cho bạn thông tin, về thời gian thực. Và không phải thời gian thực dữ liệu ngay sẽ chỉ hiển thị một ngày sau khi
EDIT cho 3,0:
tôi thấy một số điều có thể hữu ích cho bạn:
Chúng tôi vừa đi qua vấn đề này và điều này là hơi ra của ngày do đó, đây là câu trả lời được cập nhật. Vấn đề chúng tôi đã có sau khi làm theo các hướng dẫn trên trang web của Google Analytics, họ hướng dẫn bạn để thêm các tập tin sau đây GAI.h
, GAIDictionaryBuilder.h
, GAILogger.h
, GAITrackedViewController.h
, GAITracker.h
và libGoogleAnalytics_debug.a
thư viện. Những gì họ hoàn toàn quên để bao gồm trên các hướng dẫn trang web là một trong những nơi bạn có để bao gồm libGoogleAnalyticsServices.a
thư viện.Điều này được bao gồm trong bản tải xuống nén nhưng không có hướng dẫn để chỉ ra bao gồm điều này trong phiên bản gỡ lỗi.
Lưu ý: Trong readme.txt libGoogleAnalyticsServices.a
chỉ là gọi là libGoogleAnalytics.a
Google đã thất bại trong việc cập nhật tài liệu của họ để bao gồm tên mới hoặc các hướng dẫn đúng mà cho biết điều này là cần thiết trong debug.
Files and Libraries rằng hầu hết được bao gồm
GAI.h
GAIDictionaryBuilder.h
GAIFields.h
GAILogger.h
GAITrackedViewController.h
GAITracker.h
libGoogleAnalytics.a // Also know as libGoogleAnalyticsServices.a
libGoogleAnalytics_debug.a

cộng thông tin:
Tôi khá chắc chắn google vẫn chưa cung cấp một phiên bản arm64 của của họ libGoogleAnalyticsServices.a
, điều này thực sự gây phiền nhiễu ... nó có số được wee ks kể từ khi công chúng phát hành Xcode 5GM.
Hiện tại, tôi đoán chỉ xây dựng cho armv7, armv7 hoặc xóa google phân tích cho đến khi chúng ra khỏi quần.
Đây là iOS Getting Started Guide. để triển khai.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 0;
// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];
// Initialize tracker.
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-Y"];
}
Để tự gửi một cái nhìn màn hình, thiết lập các giá trị trường màn hình trên tracker, sau đó gửi các hit:
// May return nil if a tracker has not already been initialized with a
// property ID.
id tracker = [[GAI sharedInstance] defaultTracker];
// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName
value:@"Home Screen"];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
Hoặc tự động đo màn hình:
Tự động đo lường xem như màn hình sử dụng lớp học GAITrackedViewController
. Có mỗi bộ điều khiển chế độ xem của bạn mở rộng GAITrackedViewController
và thêm thuộc tính có tên screenName. Thuộc tính này sẽ được sử dụng để đặt trường tên màn hình. theo dõi
//
// MyViewController.h
// An example of using automatic screen tracking in a ViewController.
//
#import "GAITrackedViewController.h"
// Extend the provided GAITrackedViewController for automatic screen
// measurement.
@interface AboutViewController : GAITrackedViewController
@end
//
// MyViewController.m
//
#import "MyViewController.h"
#import "AppDelegate.h"
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Set screen name.
self.screenName = @"Home Screen";
}
// Rest of the ViewController implementation.
@end
sự kiện:
link
Để gửi một sự kiện vào Google Analytics, sử dụng GAIDictionaryBuilder.createEventWithCategory: hành động: label: giá trị: và gửi hit, như trong ví dụ này:
// May return nil if a tracker has not already been initialized with a property
// ID.
id<GAITracker> = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"button_press" // Event action (required)
label:@"play" // Event label
value:nil] build]]; // Event value
Chỉ cần lưu ý, bạn đang đặt trackUncaughtExceptions 2 lần. – Ricardo
Tôi hy vọng rằng bạn đã có một phiên bản làm việc của GA, nhưng chắc chắn, và đối với những người khác, tôi đã cập nhật câu trả lời của tôi cho v3. – incmiko