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

WebGL: measurement protocol not working correctly

vasyaPP opened this issue · comments

commented

I'm using GA plugin in my WebGL game and discovered that sessions and events do not count correctly. After some research I located to the problem place.

Measurement protocol required cid parameter in url. Currently in https://github.com/googleanalytics/google-analytics-plugin-for-unity/blob/master/source/Plugins/GoogleAnalyticsV4/GoogleAnalyticsMPV3.cs#L62 it's defined as clientId = SystemInfo.deviceUniqueIdentifier. But in webgl builds SystemInfo.deviceUniqueIdentifier always equals "n / a".

I fixed it by creating a random guid for clientId class member.

#if UNITY_WEBGL

clientId = PlayerPrefs.GetString(WebglUidKey, string.Empty);

if (clientId == string.Empty) {

  clientId = Guid.NewGuid().ToString();

  PlayerPrefs.SetString(WebglUidKey, clientId);

}

#else

clientId = SystemInfo.deviceUniqueIdentifier;

#endif