Google Analytics does not work in Webview in an iOS application.

Let me start by saying that I know how to use the iOS SDK, so please don’t respond to this with “just use the SDK”. I want to know why Google Analytics is not working.

Here is my setup. I have a web app that is also baked into an Android app and an ios app through webview. I use cordova. Android application works fine with GA JS code. The web works just fine. However, from iOS, events or pageviews are not displayed. I heard that GA is domain bound, so is iOS Webview doing something under the hood in the domain?

I was going to attach my code snippet, but it is coffeescript in several classes, so I just paste the compiled js

Analytics.prototype.track = function(args) { window._gaq.push(args); }; Analytics.track(['_trackEvent', 'SubscriptionModal', "Closed", data]); 

This works great on the Internet and Android, so it is not JS. I set GA _setDomainName to "focusatwill.com" and see that both ios and web have the domain "www.focusatwill.com"

I read online a few people who talked about this problem, and everyone says that they just use the SDK. I am looking for a reason why this is not working. How do you fix it to use JS?

change

I should mention that html and JS are not baked on the device, i.e. they do not have a local url, but they are served from our web server

+6
source share
1 answer

Safari on iOS6 + blocks third-party cookies by default, and I’m sure that web browsing too.

Make sure that the init method of AppDelegate.m has something similar to the following:

 NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 

This is from a standard template created by Cordova 3.0.9, but may not be available if you are using a version prior to iOS6. It sets a cookie policy for the application, which should override the system default.

0
source

Source: https://habr.com/ru/post/948276/


All Articles