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.
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.
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.
Anyone have any experience with analytics on hybrid apps or alternative solutions.
Thanks
Use Tag Manager with Google Analytics and Firebase. To get the latest mobile app report features in Google Analytics, use Firebase in your Android and iOS apps. Once enabled in your app, Google Analytics will automatically collect and report on built-in events and user properties.
Hybrid approach reduces cost of development and time-to-market by simplifying the codes easily usable on multiple platforms. The app doesn't require interfacing directly with device drivers using APIs and plugins.
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.
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.
So the javascript to track Google Analytics interactions could look something like this.
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.
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.
- (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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With