- I don't see the event data that I would expect to see on my Analytics Dashboard. I want to confirm that my device is sending Analytics events from my Unity game.
You might see delays in data (or no data at all) appearing on your Unity Analytics Dashboard, and want to confirm that your mobile application is indeed sending events. You also might want to confirm that expected events are firing at the correct location within your game.
Charles Proxy is a great utility that allows you to monitor network activity on your mobile device from your PC. When configured correctly, you are able to see individual network requests and responses as they are generated on your mobile device. This can be handy to confirm that your game is sending events over the network to the Unity data center. This article will explain the steps to get Charles Proxy installed and operating successfully and will give you the ability to watch individual network calls from your mobile device as they are being made during your game execution.
The general steps are as follows, details below under More Information.
- Install and configure Charles Proxy on your PC or Mac
- Configure your Android or iOS mobile device to use your PC as a network proxy
- Launch your game and monitor the network activity in Charles
Here are the detailed steps to install and configure Charles Proxy
1. Install Charles Proxy on your PC or Mac. You can install it from here . The 30 day free trial is fully functional, but will only run for 30 minutes at a time.
2. Upon launching, you should see a screen like this. Note the two toolbar buttons, Clear events and Start/Pause recording. Note that the Structure tab is selected which groups the events by URL. The Sequence tab shows all events in chronological order.
3. If you don't see the Request and Response tabs on the right pane, go to Preferences/Viewers and uncheck the two Combine checkboxes as shown here:
4. To avoid seeing local traffic on the PC/Mac, from the Proxy menu, uncheck Windows Proxy/macOS Proxy.
5. Enable SSL proxying by navigating to the Proxy menu and choosing SSL Proxying Settings. On the next dialog box, check Enable SSL Proxying, and the settings as in the following image. You type in *.unity3d.com in first field, and * in the port field. When you click OK the : is added for you.
6. We will now configure your mobile device to use your PC as the network proxy.
- Two-finger swipe from the top of the device (if using the default UI)
- Choose the gear icon from the top of the screen (to go to Settings)
- Select Wi-Fi
- Select the same Wifi network that you are using on your PC using a long press which will provide the additional option to Modify Network
- Check Show Advanced Options which will allow you to set a Manual Proxy
- For Proxy hostname, use the IP address of your PC. You can easily obtain this value from within Charles by selecting Local IP Address from the Help menu
- For Proxy port, use the Charles default of 8888
- Select Save
- Stop and Restart Wi-Fi on the device by selecting the On/Off slider (or restart the device)
- You will likely receive a pop up in Charles asking to to Allow or Deny the device requests
- On the device, browse to chls.pro/ssl to download and install the Charles certificate. Name the certificate to your choosing.
- On the PC/Mac, ensure that Recording is enabled.
- On the device, launch your game.
- You should now start to see the events being recorded (see note on Android Nougat below). You should see requests being sent to one or more of the following URLs. Expand them to see the actual events.
https://api.uca.cloud.unity3d.com (generally the one you want to monitor)
If you are running Android Nougat 7, you will need to perform the additional steps:
- In your Unity project, add the following to the
applicationelement in your android manifest:
- Create a
network_security_config.xmlfile in the following folder:
- Contents of network_security_config.xml:
<network-security-config> <base-config> <trust-anchors> <certificates src="user" /> <certificates src="system" /> </trust-anchors> </base-config> </network-security-config>
- Build and deploy the app using Android Studio
- UPDATE - CharlesProxy.unitypackage has been attached to this article. When added to your project, it modifies the AndroidManifest for you. You'll want to remove the package before you release your app, and is provided as-is.
The steps are similar as above.
- Go to Settings/Wi-Fi
- Next to the Wifi network name, click the "i" (information) icon
- Scroll down to the HTTP PROXY section
- Set the Server and Port as above (do not check Authentication)
- Stop and then start Wifi
- Download and install the Charles certificate as above by browsing to chls.pro/ssl on the device
- Trust the certificate by going to Settings/General/About/Certificate Trust Settings, and select Enable Full Trust for Root Certificates for the Charles Proxy certificate.
- Launch your Analytics-enabled Unity application. You should begin to see the events listed in Charles.
For PC - Windows 10:
- In Charles, from the Help menu, choose Install Charles Root Certificate
- In the subsequent dialog, choose Install Certificate. Choose Current User, and choose Automatically select the certificate store, then Finish.
- We will now run the Windows Certificate Manager from the Windows Start Menu, All Apps, Windows System, and Run. In the Run dialog, enter certmgr.msc and click OK.
- By clicking and dragging, move the Charles Proxy CA certificate from the Personal/Certificates store to the Trusted Root Certification Authorities/Certificates store as shown below. Charles should now capture and display network traffic on your PC
@..., why fiddler isn't option ?
Use Fiddler if you are familiar, it's a great tool also
For Android, we might elaborate on this part of instruction:
> On the device, browse to chls.pro/ssl to download and install the Charles certificate. Name the certificate to your choosing. (end of quote)
The certificate did download, but didn't show any visible queue for installation. In order to install the certificate, I needed to additionally go to Settings > Security > Encryption > Install a certificate > CA certificate, then select & install the certificate file as previously downloaded in chls.pro/ssl.
In case these macos steps helps anyone like it helped me for macos -> https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/
What's the official Unity's solution for adding "network_security_config.xml" to the build after Unity 2021 removed the possibility to add resources under the Plugin/Android/res folder?
One simple way is to convert these resources to aar using android tools but I'm just wondering if there is an alternative provided by Unity.
I will check and will update the article if I find anything. Thanks for the heads up.
Any update on how to add "network_security_config.xml" in Unity 2021? we need a template how to create androidlib or aar with network_security_config.xml inside.
Please sign in to leave a comment.