简体   繁体   中英

Tracking Hybrid Apps with Google Analytics

I have an app with some native screens and some additional content I load via UIWebView. I am trying to track both native and web content into the same google analytics account. I'm able to create an account that tracks web and I can create a separate account that tracks the native screens. How can I combine this tracking into a single account?

Track web code using ga.js and native code using GA iOS SDK

You should have a UA account ID of the sort "UA-xxxxxxxx". If you use this same Analytics tracking ID across your web app & native iOS app, all your data will end up in the same Google Analytics bucket. Obviously, you'll have to use the javascript library in your web app and native SDK in your iOS app.

Alternative Solution (I dont really recommend this)

You can you have your web app pipe in your GA events into your iOS app. How I did this in the past was like so.

  1. I created a special GA codes like myapp://ga-pageview/<pagename> and myapp://ga-event/event_category/event_name .

  2. Use the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType: to intercept these "special" urls and do the GA callback natively.

  3. In the web app, whereever you need you need call a GA event, create an iframe with the myapp://ga-* url scheme above. Then remove that iframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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