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:
- Check the proxy documentation
- Install via your terminal
brew install mitmproxy
. You’ll need Homebrew on your Mac - Start your proxy with the command:
mitmweb
in your terminal - Open your OS X settings panel and go to
sharing
- In
sharing
activate internet sharing and share your connection via LAN on your WiFi. Your WiFi needs to be active! - Open
network
in your OS X settings panel and note your IP address - 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… - 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. Theport
should be8080
- Check if MITM is running in your terminal!
- Now visit with your mobile device web browser to mitm.it and click to install the correct SSL certificate
- After installation of your certificate you still have to enable the certificate on your iPhone. To verify go to
Settings
→General
→VPN & Device Management
→Profile
(iOS 15) - Next step is to turn on the toggle button (on the bottom) to trust the mitm root certificate:
Settings
→General
→About
→Trusted Certificates
→Certificate Trust Settings
(iOS 15) - 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:
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 Privacy
→ Tracking
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!
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:
- After installation of your certificate you still have to enable the certificate on your Android device. Navigate to
Settings
→WiFi
. Long press on network name and tap on Modify network - 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
- 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
- Last step is to Open the certificate
- 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:
- Start your proxy with the command:
mitmweb
in your terminal - Open your OS X settings panel and go to
sharing
- In
sharing
activate internet sharing and share your connection via LAN on your WiFi - On your iPhone go to:
Settings
→General
→About
→Certificate Trust Settings
. Under “Enable full trust for root certificates,” turn on trust for the ‘mitmproxy’ certificate - Go to your mobile device and connect to your shared WiFi network (Computer Name in your OS X settings panel)
- 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.
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:
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:
Settings
→General
→About
→Certificate Trust Settings
. Under “Enable full trust for root certificates,” turn off trust for the ‘mitmproxy’ certificate.
- In your terminal stop mitmweb with
CONTROL - C
- Disable
Internet Sharing
on your Mac