googleanalytics / google-analytics-plugin-for-unity

Google Analytics plugin for the Unity game creation system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReferenceException trying to clear tracker parameter (iOS)

nicolasjinchereau opened this issue · comments

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

@param value The value to set for the parameter. If this is nil, the
value for the parameter will be cleared.
*/
- (void)set:(NSString *)parameterName
value:(NSString *)value;

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

void set(const char * parameterName, const char * value ) {
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:[NSString stringWithUTF8String:parameterName]
value:[NSString stringWithUTF8String:value ]];
}

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

public void _set(string parameterName, object value){
set(parameterName, value.ToString());
}

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

public void SetTrackerVal(Field fieldName, object value){
handler._set(fieldName.ToString(), value);
}