Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor Google Analytics requests on an iPhone Application

I am trying to monitor the Google Analytics request on an iPhone application and for some reason I don't see any of GA the requests. However I can see and uniquely identify the traffic on the google analytics interface. I have tried using several technics including using Fiddler/Charles as a proxy and overlap the computer ip. While I can see many http request using this technic, I don't see any request that are related to Google Analytics.

What can be done to capture these requests?

Note: As far as I know, there is no iOS app to capture HTTP request on the actual device.

like image 475
Tomer Avatar asked Dec 12 '11 10:12

Tomer


2 Answers

The problem is that the tracking calls that the Google Analytics SDK makes are not using the iOS HTTP proxy.

If GA tracking calls doesn't use the iOS proxy they obviously won't be sent to Charles (or Fiddler or whatever) and it can't track anything. The only way to monitor these calls is to do something like share your ethernet internet connection on your computer to your iOS device wirelessly and use a tool like ngrep or WireShark to monitor the traffic coming through your wireless interface (usually en1 on a Mac). Here's an example ngrep command:

sudo ngrep -d en1 port 80 | grep --color -E -C 3 '(google|utm.gif)'

(You can easily install ngrep via homebrew on a Mac)

Or with Wireshark you can start monitoring your wireless interface (en1 on a Mac) and type "http" into the "Filter:" box to filter down to http traffic.

If you have the source code for the app then another option to avoid 'internet connection sharing' is to run the app via the iOS Simulator in Xcode on your Mac so that it uses your Mac's internet connection. The GA code actually still refuses to use the OSX-configured proxy (i.e., you still can't use Charles) but you can then use ngrep or Wireshark (as above) on your Mac without having to set up internet connection sharing.

Here's a post on my blog with more details: Monitoring Google Analytics for iOS

like image 121
Jordan Brough Avatar answered Sep 19 '22 15:09

Jordan Brough


Google Analytics does request via HTTPS -> SSL encrypted. You should in fact see their requests using Charles. Just, you won't be able to see the content of those requests.

To negate your note right away; you can certainly see HTTP/s requests from the device itself as well using Charles.

See this blog entry for more on Charles' configuration.

Make sure you understand the fundamental difference between HTTP and HTTPS.

Edit: I was all wrong. Google Analytics does not use HTTPS for the tracking but plain HTTP (TCP Port 80). I have yet to find out on why the tracking requests are not visible when using Charles. They are however visible when using Wireshark.

-> Use Wireshark for tracing Google Analytics activity.

To get that accomplished, I am sharing the internet connection from my Mac with my iOS device as follows:

System Preferences -> Sharing -> Internet Sharing -> Share your connection from:Ethernet, To computers using:Wifi

Once connected, I make sure to minimize the network traffic of the Mac itself to prevent noisy tracing.

The rest is Wireshark magic and a bit hard to describe off the head (can not do it at this moment).

like image 39
Till Avatar answered Sep 20 '22 15:09

Till