googleanalytics / google-analytics-plugin-for-unity

Google Analytics plugin for the Unity game creation system
Apache License 2.0
385 stars 140 forks source link

NullReferenceException trying to clear tracker parameter (iOS) #161

Open nicolasjinchereau opened 6 years ago

nicolasjinchereau commented 6 years ago

To clear a parameter, you should pass nil to value:

https://github.com/googleanalytics/google-analytics-plugin-for-unity/blob/49a1ddf65eb99ec860ff42c15ff1ff5e4a4eebf2/source/Plugins/iOS-nobitcode/GAITracker.h#L33-L37

But first, this call is made, which calls +(NSString)stringWithUTF8String on value, which will throw when null is passed.

https://github.com/googleanalytics/google-analytics-plugin-for-unity/blob/49a1ddf65eb99ec860ff42c15ff1ff5e4a4eebf2/source/Plugins/iOS-bitcode/GAIHandler.m#L108-L113

But before calling those two, you must call this in C#, which calls ToString() on the value without checking if it's null.

https://github.com/googleanalytics/google-analytics-plugin-for-unity/blob/5a5caee6cc4a0188430ca65ea1c376288bca5fbf/source/Plugins/GoogleAnalyticsV3/GAIHandler.cs#L95-L97

Finally, SetTrackerVal, which should be able to accept null to clear parameters, but crashes due to aforementioned problems.

https://github.com/googleanalytics/google-analytics-plugin-for-unity/blob/5a5caee6cc4a0188430ca65ea1c376288bca5fbf/source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsiOSV3.cs#L124-L126