2014-02-14 35 views
2

我希望問題很清楚。否則,我很抱歉。 我已經制作了一款在Android和iOS上運行良好的Phonegap應用。它裏面有很多html文件,我沒有任何興趣跟蹤它們的使用,但是我知道應用程序,語言,設備,版本......以及所有這些東西的擴散這隻能與調用cordova插件的視圖一起提供。如何將Google Analytics整合到iOS Phonegap應用程序的MainView(不在裏面)?

在Android上,按照包含Google Analytics的標準說明進行操作非常簡單。

但我還沒有找到在iOS上做到這一點的方法。下列標準指令時(https://developers.google.com/analytics/devguides/collection/ios/v3/)我不知道該怎麼辦到達這裏的時候: enter image description here

因爲什麼,我覺得是:

enter image description here

當CDVViewController看,我們看到:

enter image description here

我不知道我必須把庫,如果在「app.xcodeproj」文件Ø r在相應的「CordovaLib.xcodeproj」中,依此類推。我已經嘗試了一些可能性,但沒有任何結果。

我必須承認,我知道很少的iOS編程,只是爲了讓應用程序的PhoneGap,然後按照任何形式的輔導,以提高他們的...

我也嘗試過其他的解決方案,(不插件...)但沒辦法。

有沒有辦法做到這一點?提前致謝。

回答

0

最後,我得到了解決方案!

我所做的是:

  1. 按照https://developers.google.com/analytics/devguides/collection/ios/v3/

從指令的步驟1和2,我不知道這是否是相關的,但在步驟1中,我把SDK在App的類文件夾文件(這裏是AppDelegate.h ...)

在步驟2,記得把開頭:

#import "GAI.h" 
  1. En 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]]; 


} 

就是這樣。現在你可以關注你的應用程序,甚至是科爾多瓦處理的內嵌頁面。

我得給我​​的兄弟和http://blog.fltlab.net/2012/04/10/phonegap-and-googleanalytics/誰給了我提示的人的學分。

更新:更新到Xcode 5.1後,科爾多瓦3.4(我在2.9),我不得不重拍我的科爾多瓦應用程序,並重復所有這些步驟;但我必須在步驟1鏈接另一個庫(libsqlite3.dylib)。

相關問題