简体   繁体   English

如何将Google Analytics(分析)集成到iOS Phonegap应用的MainView中(而不是内部)?

[英]How to integrate Google Analytics in the MainView (not inside) of a iOS Phonegap App?

I hope the question is clear enough. 我希望这个问题足够清楚。 Otherwise, I apologize. 否则,我深表歉意。 I've made a Phonegap app that works fine in Android and iOS. 我制作了一个Phonegap应用,该应用在Android和iOS上都可以正常运行。 It has a lot of html files inside, and I don't have any interest in tracking the use of them, but I do have it in knowing the difusion of the App, languages, devices, versions,... and all that stuff that can be provided only with the view that calls the cordova plugin. 它内部有很多html文件,我对跟踪它们的使用没有兴趣,但是我确实知道应用程序,语言,设备,版本等的分散性。只能在调用cordova插件的视图中提供。

On Android it's been very easy, following the standard instructions to include Google Analytics. 在Android上,按照标准说明包含Google Analytics(分析)非常简单。

But I haven't found a way to do it on iOS. 但是我还没有找到在iOS上执行此操作的方法。 When following standard instructions ( https://developers.google.com/analytics/devguides/collection/ios/v3/ ) I don't know what to do when arriving here: 遵循标准说明( https://developers.google.com/analytics/devguides/collection/ios/v3/ )时,我不知道该怎么办: 在此处输入图片说明

Because what I find is: 因为我发现的是:

在此处输入图片说明

When looking at CDVViewController, we see this: 当查看CDVViewController时,我们看到以下内容:

在此处输入图片说明

I wonder where I'd have to place the libraries, if in the "app.xcodeproj" file or in the corresponding "CordovaLib.xcodeproj", and so on. 我想知道如果将库放置在“ app.xcodeproj”文件或相应的“ CordovaLib.xcodeproj”中,依此类推。 I' ve tried, blindly, several posibilities, but nothing is working. 我已经盲目地尝试了几种可能性,但是没有任何效果。

I must recognize that I know very little of iOS programming, just enough to make Phonegap apps, and then follow any kind of tutorials to improve them... 我必须认识到,我对iOS编程了解甚少,足以制作Phonegap应用,然后按照任何类型的教程进行改进...

I've also tried other solutions, (without plugins...) but no way. 我也尝试了其他解决方案,(没有插件...),但是没有办法。

Is there any way to do it? 有什么办法吗? Thanks in advance. 提前致谢。

At last, I got the solution! 最后,我找到了解决方案!

What I did was: 我所做的是:

  1. Follow the steps 1 and 2 from the instructions in https://developers.google.com/analytics/devguides/collection/ios/v3/ 按照https://developers.google.com/analytics/devguides/collection/ios/v3/中的说明执行步骤1和2。

I don't know if it's relevant but in the step 1, I placed the SDK files in the Classes Folder of the App (where is AppDelegate.h ...) 我不知道它是否相关,但是在步骤1中,我将SDK文件放置在App的Classes文件夹中(在AppDelegate.h ...中)

In the step 2, remember to put at the beginning: 在第2步中,请记住放在开头:

   #import "GAI.h"
  1. En MainViewController.m put at the beginning 将MainViewController.m放在开头

     #import "GAI.h" #import "GAIFields.h" #import "GAITracker.h" #import "GAIDictionaryBuilder.h" 

Then comment out the lines: 然后注释掉这些行:

/*

- (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];
}

*/

And, at last, before the line 最后,在上线之前

  return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];

insert this: 插入此:

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]];


}

And that's all. 就这样。 Now you can follow your app, and even the insided pages handled by cordova. 现在,您可以关注您的应用程序,甚至可以关注cordova处理的内页。

I have to give the credits to my brother and the people of http://blog.fltlab.net/2012/04/10/phonegap-and-googleanalytics/ who gave me the hints. 我必须感谢我的兄弟和http://blog.fltlab.net/2012/04/10/phonegap-and-googleanalytics/给我提示的人们。

UPDATE: after updating to Xcode 5.1, Cordova 3.4 (I was on 2.9) , I had to remake my cordova apps, and repeat all these steps; 更新:更新到Xcode 5.1,Cordova 3.4(我当时是2.9)之后,我不得不重新制作我的cordova应用程序,并重复所有这些步骤; but I had to link another library (libsqlite3.dylib) at step 1. 但是我必须在步骤1链接另一个库(libsqlite3.dylib)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM