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

Commit

Permalink
Merge branch 'release/1.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
grooze committed Jun 1, 2020
2 parents c4e088c + 8c16ad0 commit 698f861
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
4 changes: 2 additions & 2 deletions appmetr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 11700
versionName "1.17.0"
versionCode 11800
versionName "1.18.0"
}
buildTypes {
release {
Expand Down
64 changes: 38 additions & 26 deletions appmetr/src/main/java/com/appmetr/android/AppMetr.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,9 @@ public static void attachProperties() {
*/
public static void attachProperties(JSONObject properties) {
try {
if (properties == null) {
properties = new JSONObject();
}

properties = fillProperties(properties);
JSONObject action = new JSONObject().put("action", "attachProperties");
action.put("properties", properties);
properties.put("$version", ContextProxy.AppVersion);

if (!properties.has("$country")) {
properties.put("$country", Locale.getDefault().getCountry());
}

if (!properties.has("$language")) {
properties.put("$language", Locale.getDefault().getLanguage());
}

if(!properties.has("$locale")) {
properties.put("$locale", Locale.getDefault().toString());
}

getInstance().track(action);
} catch (JSONException error) {
Log.e(TAG, "attachProperties failed", error);
Expand All @@ -183,7 +166,7 @@ public static void attachProperties(JSONObject properties) {
* Method for tracking game event as "track session" without parameters
*/
public static void trackSession() {
getInstance().trackSessionImpl(null);
trackSession(null);
}

/**
Expand All @@ -192,14 +175,22 @@ public static void trackSession() {
* @param properties - properties for event
*/
public static void trackSession(JSONObject properties) {
try {
properties = fillProperties(properties);
} catch (JSONException error) {
Log.e(TAG, "trackSession fill properties failed", error);
}
getInstance().trackSessionImpl(properties);
}

/**
* Method for tracking game event as "track level" with parameters.
*
* @param level - parameter required for this event. Displays player's level.
*
* @deprecated Use attachProperties with $level=level instead
*/
@Deprecated
public static void trackLevel(int level) {
trackLevel(level, null);
}
Expand All @@ -210,16 +201,17 @@ public static void trackLevel(int level) {
*
* @param level - parameter required for this event. Displays player's level.
* @param properties - additional parameter for this event.
*
* @deprecated Use attachProperties with $level=level instead
*/
@Deprecated
public static void trackLevel(int level, JSONObject properties) {
try {
JSONObject action = new JSONObject().put("action", "trackLevel");
action.put("level", level);
if (properties != null) {
action.put("properties", properties);
}

getInstance().track(action);
try {
if(properties == null)
properties = new JSONObject();
properties.put("$level", level);
attachProperties(properties);
} catch (JSONException error) {
Log.e(TAG, "trackLevel failed", error);
}
Expand Down Expand Up @@ -401,4 +393,24 @@ private static void trackLaunchIntent(Activity activity) {
Log.e(TAG, "TrackLaunchIntent failed", error);
}
}

private static JSONObject fillProperties(JSONObject properties) throws JSONException {
if(properties == null) {
properties = new JSONObject();
}
properties.put("$version", ContextProxy.AppVersion);

if (!properties.has("$country")) {
properties.put("$country", Locale.getDefault().getCountry());
}

if (!properties.has("$language")) {
properties.put("$language", Locale.getDefault().getLanguage());
}

if(!properties.has("$locale")) {
properties.put("$locale", Locale.getDefault().toString());
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,29 @@ public static void trackSession(String serializedProperties) {

/**
* Method for tracking game event as "track level" without parameters
*
* @deprecated Use attachProperties with $level=level instead
*/
@Deprecated
public static void trackLevel(int level) {
try {
AppMetr.trackLevel(level);
AppMetr.attachProperties(new JSONObject().put("$level", level));
} catch (final Throwable error) {
Log.e(TAG, "trackLevel failed", error);
}
}

/**
* Method for tracking game event as "track level" with parameters
*
* @deprecated Use attachProperties with $level=level instead
*/
@Deprecated
public static void trackLevel(int level, String serializedProperties) {
try {
AppMetr.trackLevel(level, new JSONObject(serializedProperties));
JSONObject properties = new JSONObject(serializedProperties);
properties.put("$level", level);
AppMetr.attachProperties(properties);
} catch (final Throwable error) {
Log.e(TAG, "trackLevel failed", error);
}
Expand Down
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.appmetr.android.demo"
minSdkVersion 14
targetSdkVersion 28
versionCode 11700
versionName "1.17.0"
versionCode 11800
versionName "1.18.0"
}
buildTypes {
release {
Expand Down

0 comments on commit 698f861

Please sign in to comment.