Start a new topic

Integrating with Google Analytics

Integrating with Google Analytics

I have wrapped a sample app  (which plays video, with an option to pause) into an ios app and its working fine. I wanted to further enable google analytics (defined as a mobile app) to gather stats. As part of IOS GA SDK, I am able to send events on launch etc. But once index.html / snappingvideo.js takes over (which is HTML) I am not able to send google analytics event from JS (using google analytics.js) file. 

If I open index.html on normal browser, the event is published to GA, but the moment same code is wrapped as part of ios app, nothing appears in GA.

Is there some best practice to pass control from JS (snappingvideo.js) back to IOS for the app event to be captured. Hoping to be a solved/ known problem.

Thanks in advance


I recommend you to use latest GoogleAnalytics JS library and track actions directly in your AR experience's code (using ga('send', ...) ).
That way you can use same tracking on all clients.

Hi Andreas

Thansk for your reply. I am also working with Shishir on this one. We have tried doing that but for some reason the call never leaves the App.

I tried to debug but there is no network call from the app. It seems quite weird because the same code works as a web page but as soon as we wrap it in an app it stops.

Would really appreciate your help. 

By default google analytics uses same protocol as used for loading the html file it sits in.
Ensure to set https protocol when loading ga-assets.


Best regards

Hi Andreas

Thanks for the reply. 

We have debugged this quite an extent. The problem is that when we call the ga.send method it calls the task to checkProtocol. And in case of the app the protocol is file:// instead of either http:// or https://. 

And at this point ga aborts the process as described at this page

We are calling the ga send, on the click of a button inside the createWWWbutton method within out js. The analytics.js does load as we can see it in the loaded resources while debugging.

We would like to understand how we can get around this problem. 

Any ideas?




Technically the AR experience is executed in a native iOS/Android webview.
Please ensure to use http(s) or relative paths where necessary when you plan to bundle the ssource in your application.
The issue you describe is not related to the AR SDK but more of a general Webview ga question. Please check out other forums, e.g. stackoverflow,  for more details.

Best regards

Thanks Andreas. Its not a AR SDK problem and we have found the reason / solution as well. Posting it here for someone's else use

ga.js send function by default uses checkProtocolTask which requires the protocol to be either http or https (// relative protocol syntax). But in case of this sample wiki app, the protocol is resvoled to file:// and hence the calls get aborted. 

So one way to bypass this is to disable this task using ga('set', 'checkProtocolTask', null); // Disables file protocol checking

Login or Signup to post a comment