Debugging your app analytics with a proxy

Debugging your app is notoriously difficult and way more complex than the web counterpart, but there are possibilities.

You can run local virtual devices if you have access to the source code or to install files as an IPA (iOS) or APK (Android) file. When running a local device you can use the console of XCode or Android Studio to debug your app.

At the moment you don’t have access to source code or install files, your only option is to use a proxy. There are multiple proxies to choose from, but I’m using the open source “Men in the Middle” (MITM) proxy.

Install MITM on iOS / MacOS

You need to install the proxy via the terminal, but no worries. There is also a Web Interface after installation to monitor your app traffic.

So, follow the next steps for the first time installation of the proxy:

  1. Check the proxy documentation
  2. Install via your terminal brew install mitmproxy. You’ll need Homebrew on your Mac
  3. Start your proxy with the command: mitmweb in your terminal
  4. Open your OS X settings panel and go to sharing
  5. In sharing activate internet sharing and share your connection via LAN on your WiFi. Your WiFi needs to be active!
  6. Open network in your OS X settings panel and note your IP address
  7. Go to your mobile device and find and connect to your shared WiFi network (Computer Name in your OS X settings panel). In Sharing enable WiFi and set your WiFi password in WiFi Options…
  8. When your mobile device is connected to your Mac shared WiFi network edit your proxy settings. For Server you need to add your IP address of step 6. The port should be 8080
  9. Check if MITM is running in your terminal!
  10. Now visit with your mobile device web browser to mitm.it and click to install the correct SSL certificate
  11. After installation of your certificate you still have to enable the certificate on your iPhone. To verify go to SettingsGeneralVPN & Device ManagementProfile (iOS 15)
  12. Next step is to turn on the toggle button (on the bottom) to trust the mitm root certificate: SettingsGeneralAboutTrusted CertificatesCertificate Trust Settings (iOS 15)
  13. Now you are able to open your app and you should see your requests coming from your app in the web interface of the MITM proxy

Find your ip address –to use in step 8– in your MacOS network settings:

macOS network settings

Start MITM web via the terminal

Start MITM web via the terminal

Check your Privacy settings in iOS

Check if you have enabled any privacy features in iOS which could block the Google Analytics tracking in MITM. In PrivacyTracking the app you want to track should be enabled (toggle on) in the list. Also check if you have any add blockers installed on your iPhone. If so, disable them temporarily!

Check your Privacy Settings for App Tracking

Install MITM on Android / MacOS

You need to install the proxy via the terminal, but no worries. There is also a Web Interface after installation to monitor your app traffic.

So, follow the next steps for the first time installation of the proxy:

The first [1-9] steps are identical as the steps above for iOS/ MacOS. The next steps are specific for Android:

  1. After installation of your certificate you still have to enable the certificate on your Android device. Navigate to SettingsWiFi. Long press on network name and tap on Modify network
  2. Now you have to change the Proxy Settings. Tap on Show Advance options and you’ll find Host Name, Port. Use the same information as we did when setting up the iPhone
  3. Open your favorite browser (e.g. Chrome) on your Android device and go to the address: mitm.it. This is similar to what we did on Safari while setting up the iPhone
  4. Last step is to Open the certificate
  5. Now you are able to open your app and you should see your requests coming from your app in the web interface of the MITM proxy

Run your MITM proxy (after installation)

Next time when you have the need to debug your app, it’s easier to start and less steps are needed:

  1. Start your proxy with the command: mitmweb in your terminal
  2. Open your OS X settings panel and go to sharing
  3. In sharing activate internet sharing and share your connection via LAN on your WiFi
  4. On your iPhone go to: SettingsGeneralAboutCertificate Trust Settings. Under “Enable full trust for root certificates,” turn on trust for the ‘mitmproxy’ certificate
  5. Go to your mobile device and connect to your shared WiFi network (Computer Name in your OS X settings panel)
  6. Now you are able to open your app and you should see your requests coming from your app in the web interface of the MITM proxy

Internet sharing on MacOS

Start your own WiFi network by enabling Internet Sharing on your Mac.

macOS settings sharing internet

MITM web interface

In the MITM web interface you can color the requests for easier debugging. Click on the left hand on the request you want to analyze and see your (batched) request data on your right:

MITM web interface

Done testing?

When you are done with testing, don’t forget to disable the certificate on your mobile device! This is important for security reasons.

  • On your iPhone go to: SettingsGeneralAboutCertificate Trust Settings. Under “Enable full trust for root certificates,” turn off trust for the ‘mitmproxy’ certificate.
iOS trust the certificate
  • In your terminal stop mitmweb with CONTROL - C
  • Disable Internet Sharing on your Mac