使用谷歌分析与混合移动应用程序

时间:2023-02-06 15:20:29

We are in the process of turning our native iPad app into a hybrid app. Some functionality and UI will remain in native code and other functionality will be implemented in HTML that will be served from our servers and will also be available offline.

我们正在将原生iPad应用程序转变为混合应用程序。一些功能和UI将保留在本机代码中,其他功能将以HTML格式实现,这些功能将从我们的服务器提供,也可以脱机使用。

The main issue I encounter now is with using Google Analytics:
The existing native code uses the GA SDK for IOS and I planned on using the web API for the web part, however I can't find how the data from both channels can be used together in GA as the data stores seem to be distinct.

我现在遇到的主要问题是使用Google Analytics:现有的本机代码使用适用于IOS的GA SDK,我计划将Web API用于Web部件,但我无法找到如何使用来自两个渠道的数据在GA中,数据存储似乎是截然不同的。

Furthermore, I plan to use Google Analytics' Content Experiments for A/B testing the web part but conversion goals might be ones achieved in the native part.

此外,我计划使用Google Analytics的内容实验进行A / B测试Web部件,但转换目标可能是在本机部分实现的目标。

Anyone have any experience with analytics on hybrid apps or alternative solutions.

任何人都有混合应用程序或替代解决方案的分析经验。

Thanks

谢谢

3 个解决方案

#1


18  

You really want to use the SDK. It has some features that will come handy for mobile apps like crashes, play store integration. It also sends data in batches to improve battery usage and also can queue hits while the app is offline to be sent when online. You won't be able to emulate that with the Javascript implementations.

你真的想使用SDK。它具有一些功能,可以用于移动应用程序,如崩溃,游戏商店集成。它还可以批量发送数据以提高电池使用率,还可以在应用程序离线时将命中排队,以便在线时发送。您将无法使用Javascript实现来模拟它。

So what you need to write is Javascript methods that send data from the WebView back to the Native Part of the App. This other Stack Overflow thread has more detail on how to do that.

所以你需要编写的是Javascript方法,它们将数据从WebView发送回应用程序的Native部分。这个其他Stack Overflow线程有关于如何执行此操作的更多详细信息。

So the javascript to track Google Analytics interactions could look something like this.

因此,跟踪Google Analytics互动的JavaScript可能看起来像这样。

var _gaq = {};
_gaq.push = function(arr){
  var i, hit;
  hit = arr.slice(1).join('&');
  location.href = 'analytics://'+arr[0]+'?'+arr;
};

Now this will work as a replacement for your ga.js file, you can still use the same API as you use on _gaq today on your Web App, and the adapter above will sends its data to te native part of the APP. And then you just need to write the native part that will intercept that HTTP request and use the native SDK to issue the Google Analytics functions.

现在,这将作为ga.js文件的替代品,您仍然可以使用与Web应用程序上今天_gaq上使用的相同的API,上面的适配器将其数据发送到APP的本机部分。然后,您只需编写将拦截该HTTP请求的本机部分,并使用本机SDK发布Google Analytics功能。

A normal _gaq.push(['_trackPageview', '/homepage']); will become a uri like analytics://_trackPageview?/homepage, now you just need to intercept and parse that on the Native part.

正常的_gaq.push(['_ trackPageview','/ homepage']);将成为uri like analytics:// _ trackPageview?/ homepage,现在你只需要拦截并解析Native部分。

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *url = [request URL];

    NSLog(@"Hit detected %@", url.absoluteString);

    if ([[url scheme] isEqualToString:@"analytics"]) {
        id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

        if ([url.host isEqualToString:@"_trackPageview"]) {
            // Get the page from parameters and then track the native View.
            // (...)
            [tracker trackView:page];
        }
        else if ([url.host isEqualToString:@"_trackEvent"]) {
            // Get the event parameters from url parameters and then track the native GA Event.
            // (...)
            [tracker trackEventWithCategory:cat
                                 withAction:act
                                  withLabel:lab
                                  withValue:val];
        }
        // Check for all other analytics functions types
        // (...)
        // Cancel the request
        return NO;
    }
    // Not an analytics: request.
    return YES;
}

I hope it have given you a good starting point. Good luck.

我希望它给了你一个很好的起点。祝你好运。

#2


1  

Indeed a challenging configuration.

确实是一个具有挑战性

Have you looked into using analytics.js (Universal Analytics) for the web part ? Then you may be able to feed data into a single App profile

您是否考虑过将analytics.js(Universal Analytics)用于Web部件?然后,您可以将数据提供到单个App配置文件中

Else, you could send all the tracking calls from your backend, by using a server side implementation of the Measurement Protocol but you'll probably loose usage of Content Experiment !

否则,您可以通过使用测量协议的服务器端实现从您的后端发送所有跟踪调用,但您可能会放弃使用内容实验!

#3


0  

I use http://www.flurry.com/ for my apps and Google Analytics for my other stuff. I never mixed both of them in the same app but I'm guessing it's doable. I'd sugest to check out flurry first. There's a good chance it will suffice also for an hybrid app.

我使用http://www.flurry.com/获取我的应用程序,使用Google Analytics获取其他内容。我从来没有在同一个应用程序中混合使用它们,但我猜它是可行的。我想先看看乱舞。混合应用程序也很有可能就足够了。

#1


18  

You really want to use the SDK. It has some features that will come handy for mobile apps like crashes, play store integration. It also sends data in batches to improve battery usage and also can queue hits while the app is offline to be sent when online. You won't be able to emulate that with the Javascript implementations.

你真的想使用SDK。它具有一些功能,可以用于移动应用程序,如崩溃,游戏商店集成。它还可以批量发送数据以提高电池使用率,还可以在应用程序离线时将命中排队,以便在线时发送。您将无法使用Javascript实现来模拟它。

So what you need to write is Javascript methods that send data from the WebView back to the Native Part of the App. This other Stack Overflow thread has more detail on how to do that.

所以你需要编写的是Javascript方法,它们将数据从WebView发送回应用程序的Native部分。这个其他Stack Overflow线程有关于如何执行此操作的更多详细信息。

So the javascript to track Google Analytics interactions could look something like this.

因此,跟踪Google Analytics互动的JavaScript可能看起来像这样。

var _gaq = {};
_gaq.push = function(arr){
  var i, hit;
  hit = arr.slice(1).join('&');
  location.href = 'analytics://'+arr[0]+'?'+arr;
};

Now this will work as a replacement for your ga.js file, you can still use the same API as you use on _gaq today on your Web App, and the adapter above will sends its data to te native part of the APP. And then you just need to write the native part that will intercept that HTTP request and use the native SDK to issue the Google Analytics functions.

现在,这将作为ga.js文件的替代品,您仍然可以使用与Web应用程序上今天_gaq上使用的相同的API,上面的适配器将其数据发送到APP的本机部分。然后,您只需编写将拦截该HTTP请求的本机部分,并使用本机SDK发布Google Analytics功能。

A normal _gaq.push(['_trackPageview', '/homepage']); will become a uri like analytics://_trackPageview?/homepage, now you just need to intercept and parse that on the Native part.

正常的_gaq.push(['_ trackPageview','/ homepage']);将成为uri like analytics:// _ trackPageview?/ homepage,现在你只需要拦截并解析Native部分。

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *url = [request URL];

    NSLog(@"Hit detected %@", url.absoluteString);

    if ([[url scheme] isEqualToString:@"analytics"]) {
        id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

        if ([url.host isEqualToString:@"_trackPageview"]) {
            // Get the page from parameters and then track the native View.
            // (...)
            [tracker trackView:page];
        }
        else if ([url.host isEqualToString:@"_trackEvent"]) {
            // Get the event parameters from url parameters and then track the native GA Event.
            // (...)
            [tracker trackEventWithCategory:cat
                                 withAction:act
                                  withLabel:lab
                                  withValue:val];
        }
        // Check for all other analytics functions types
        // (...)
        // Cancel the request
        return NO;
    }
    // Not an analytics: request.
    return YES;
}

I hope it have given you a good starting point. Good luck.

我希望它给了你一个很好的起点。祝你好运。

#2


1  

Indeed a challenging configuration.

确实是一个具有挑战性

Have you looked into using analytics.js (Universal Analytics) for the web part ? Then you may be able to feed data into a single App profile

您是否考虑过将analytics.js(Universal Analytics)用于Web部件?然后,您可以将数据提供到单个App配置文件中

Else, you could send all the tracking calls from your backend, by using a server side implementation of the Measurement Protocol but you'll probably loose usage of Content Experiment !

否则,您可以通过使用测量协议的服务器端实现从您的后端发送所有跟踪调用,但您可能会放弃使用内容实验!

#3


0  

I use http://www.flurry.com/ for my apps and Google Analytics for my other stuff. I never mixed both of them in the same app but I'm guessing it's doable. I'd sugest to check out flurry first. There's a good chance it will suffice also for an hybrid app.

我使用http://www.flurry.com/获取我的应用程序,使用Google Analytics获取其他内容。我从来没有在同一个应用程序中混合使用它们,但我猜它是可行的。我想先看看乱舞。混合应用程序也很有可能就足够了。