[英]How to integrate Google Analytics in the MainView (not inside) of a iOS Phonegap App?
我希望這個問題足夠清楚。 否則,我深表歉意。 我制作了一個Phonegap應用,該應用在Android和iOS上都可以正常運行。 它內部有很多html文件,我對跟蹤它們的使用沒有興趣,但是我確實知道應用程序,語言,設備,版本等的分散性。只能在調用cordova插件的視圖中提供。
在Android上,按照標准說明包含Google Analytics(分析)非常簡單。
但是我還沒有找到在iOS上執行此操作的方法。 遵循標准說明( https://developers.google.com/analytics/devguides/collection/ios/v3/ )時,我不知道該怎么辦:
因為我發現的是:
當查看CDVViewController時,我們看到以下內容:
我想知道如果將庫放置在“ app.xcodeproj”文件或相應的“ CordovaLib.xcodeproj”中,依此類推。 我已經盲目地嘗試了幾種可能性,但是沒有任何效果。
我必須認識到,我對iOS編程了解甚少,足以制作Phonegap應用,然后按照任何類型的教程進行改進...
我也嘗試了其他解決方案,(沒有插件...),但是沒有辦法。
有什么辦法嗎? 提前致謝。
最后,我找到了解決方案!
我所做的是:
我不知道它是否相關,但是在步驟1中,我將SDK文件放置在App的Classes文件夾中(在AppDelegate.h ...中)
在第2步中,請記住放在開頭:
#import "GAI.h"
將MainViewController.m放在開頭
#import "GAI.h" #import "GAIFields.h" #import "GAITracker.h" #import "GAIDictionaryBuilder.h"
然后注釋掉這些行:
/*
- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
return [super webViewDidStartLoad:theWebView];
}
- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
return [super webView:theWebView didFailLoadWithError:error];
}
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
*/
最后,在上線之前
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
插入此:
NSString* path = [NSString stringWithFormat:@"%@",request];
if([path hasPrefix:@"mailto"]==NO) {
NSRange range = [path rangeOfString:@"/" options:NSBackwardsSearch];
NSString* fileName = [NSString stringWithFormat:@"/%@",[path substringFromIndex:range.location + 1]];
[[GAI sharedInstance].defaultTracker set:kGAIScreenName
value:fileName];
[[GAI sharedInstance].defaultTracker
send:[[GAIDictionaryBuilder createAppView] build]];
}
就這樣。 現在,您可以關注您的應用程序,甚至可以關注cordova處理的內頁。
我必須感謝我的兄弟和http://blog.fltlab.net/2012/04/10/phonegap-and-googleanalytics/給我提示的人們。
更新:更新到Xcode 5.1,Cordova 3.4(我當時是2.9)之后,我不得不重新制作我的cordova應用程序,並重復所有這些步驟; 但是我必須在步驟1鏈接另一個庫(libsqlite3.dylib)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.