Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Version 1.9.11
Browse files Browse the repository at this point in the history
  • Loading branch information
grooze committed Nov 30, 2017
2 parents 8e9415e + 0c4ef8e commit f3b8b59
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 12 deletions.
Binary file not shown.
113 changes: 102 additions & 11 deletions Assets/ThirdParty/Appmetr/Impl/AppmetrPluginStandalone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ public static void SetupWithToken(string token, string commandListenerName)
_appMetr = new AppMetrWin(ServerDefaultAddress, token, MobUuid, SubPlatformDefault, presister, new HttpRequestService(NewtonsoftSerializerTyped.Instance));
_appMetr.Start();
AttachProperties();
SessionInit();
}

public static void OnPause()
{
if(_appMetr != null)
SessionOnPause();
if (_appMetr != null)
_appMetr.Stop();
}

public static void OnResume()
{
if(_appMetr != null)
SessionOnResume();
if (_appMetr != null)
_appMetr.Start();
}

public static void TrackSession()
{
_appMetr.Track(new TrackSession());
TrackSession(null);
}

public static void TrackSession(IDictionary<string, object> properties)
Expand All @@ -59,7 +62,26 @@ public static void TrackSession(IDictionary<string, object> properties)
{
properties = new Dictionary<string, object>();
}

int duration = (int)(_sessionDuration / 1000L);

if (!_isFirstTrackSessionSent)
duration = -1;
else if (duration <= 0)
return;

properties.Add("$duration", duration);

_sessionDuration = 0;
SessionSaveProps();

_appMetr.Track(new TrackSession { Properties = properties });

if (!_isFirstTrackSessionSent)
{
Flush();
_isFirstTrackSessionSent = true;
}
}

public static void TrackLevel(int level)
Expand Down Expand Up @@ -152,12 +174,12 @@ public static void TrackExperimentEnd(string experiment) {}
public static bool VerifyIosPayment(string productId, string transactionId, string receipt, string privateKey) { return false; }

public static void VerifyAndroidPayment(string purchaseInfo, string signature, string privateKey, Action<bool> callback)
{
if (callback != null)
{
callback(false);
}
}
{
if (callback != null)
{
callback(false);
}
}

public static void TrackState(IDictionary<string, object> state)
{
Expand Down Expand Up @@ -246,14 +268,83 @@ private static string Get2LetterIsoCodeFromSystemLanguage() {
}
return res.ToLower();
}



//---------------------------------
// Session duration calculation
private static void SessionInit()
{
_sessionStartTick = Environment.TickCount;

_isFirstTrackSessionSent = PlayerPrefs.HasKey(PlayerPrefsSessionDuration);
_sessionDuration = PlayerPrefs.GetInt(PlayerPrefsSessionDuration, 0);
_sessionDurationCurrent = PlayerPrefs.GetInt(PlayerPrefsSessionCurrent, 0);

SessionStart();
}

private static void SessionSaveProps()
{
PlayerPrefs.SetInt(PlayerPrefsSessionDuration, (int)_sessionDuration);
PlayerPrefs.SetInt(PlayerPrefsSessionCurrent, (int)_sessionDurationCurrent);

PlayerPrefs.Save();
}

private static void SessionStart()
{
// ntrf: should not be possible if game makes TrackSession calls on start
if (_sessionDuration > 0)
{
TrackSession();
}

// remember current session as previous
_sessionDuration = _sessionDurationCurrent;
_sessionDurationCurrent = 0;
SessionSaveProps();
}

private static void SessionOnPause()
{
// Accumulate session
var tk = Environment.TickCount;
_sessionDurationCurrent = _sessionDurationCurrent + (tk - _sessionStartTick);
SessionSaveProps();

// Remember when we started session gap
_sessionStartTick = tk;
}

private static void SessionOnResume()
{
var tk = Environment.TickCount;
if ((tk - _sessionStartTick) >= SessionSplitTimout)
{
SessionStart();
}

_sessionStartTick = tk;
}


private static AppMetrWin _appMetr;
private const string ServerDefaultAddress = "https://appmetr.com/api";
private const string ServerDefaultAddress = "http://appmetr.com/api";
private const string SubPlatformDefault = "Facebook";
private const string AppmetrCacheFolder = "Appmetr";
private const string AttachPropertiesLanguage = "$language";
private const string AttachPropertiesVersion = "$version";
private const string PlayerPrefsMobUuidKey = "AppmetrUuid";
private const string PlayerPrefsSessionDuration = "AppmetrSessionDuration";
private const string PlayerPrefsSessionCurrent = "AppmetrSessionCurrent";

private static int _sessionStartTick;
private static long _sessionDuration;
private static long _sessionDurationCurrent;
private static bool _isFirstTrackSessionSent;

private const long SessionSplitTimout = 600000L;

}
}

Expand Down
Binary file modified ProjectSettings/EditorBuildSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 5.5.3p4
m_EditorVersion: 5.5.4p5

0 comments on commit f3b8b59

Please sign in to comment.