Skip to content

Commit

Permalink
Merge pull request #152 from 96andrei/AndroidCustomData
Browse files Browse the repository at this point in the history
Fixed Custom Dimensions and Custom Metrics on Android.
  • Loading branch information
baldwin628 committed Apr 4, 2017
2 parents cc437f4 + ab171cb commit ad7bf51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions source/Plugins/GoogleAnalyticsV4/GoogleAnalyticsAndroidV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public class GoogleAnalyticsAndroidV4 : IDisposable {
eventBuilder.Call<AndroidJavaObject>("setAction", new object[] { builder.GetEventAction() });
eventBuilder.Call<AndroidJavaObject>("setLabel", new object[] { builder.GetEventLabel() });
eventBuilder.Call<AndroidJavaObject>("setValue", new object[] { builder.GetEventValue() });

foreach(KeyValuePair<int, string> i in builder.GetCustomDimensions())
{
eventBuilder.Call<AndroidJavaObject>("setCustomDimension", new object[] { i.Key, i.Value });
}

foreach(KeyValuePair<int, float> i in builder.GetCustomMetrics())
{
eventBuilder.Call<AndroidJavaObject>("setCustomMetric", new object[] { i.Key, i.Value });
}

object[] builtEvent = new object[] { eventBuilder.Call<AndroidJavaObject>("build") };
tracker.Call("send", builtEvent);
}
Expand Down
2 changes: 1 addition & 1 deletion source/Plugins/GoogleAnalyticsV4/GoogleAnalyticsMPV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public IEnumerator HandleWWW(WWW request)
WWW.EscapeURL(entry.Value.ToString());
}
}
foreach(KeyValuePair<int, string> entry in builder.GetCustomMetrics())
foreach(KeyValuePair<int, float> entry in builder.GetCustomMetrics())
{
if (entry.Value != null) {
url += Fields.CUSTOM_METRIC.ToString() + entry.Key + "=" +
Expand Down
6 changes: 3 additions & 3 deletions source/Plugins/GoogleAnalyticsV4/HitBuilders/HitBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class HitBuilder<T> {

private Dictionary<int, string> customDimensions =
new Dictionary<int,string>();
private Dictionary<int, string> customMetrics = new Dictionary<int,string>();
private Dictionary<int, float> customMetrics = new Dictionary<int,float>();

private string campaignName = "";
private string campaignSource = "";
Expand All @@ -51,12 +51,12 @@ public abstract class HitBuilder<T> {
return customDimensions;
}

public T SetCustomMetric(int metricNumber, string value) {
public T SetCustomMetric(int metricNumber, float value) {
customMetrics.Add(metricNumber, value);
return GetThis();
}

public Dictionary<int, string> GetCustomMetrics() {
public Dictionary<int, float> GetCustomMetrics() {
return customMetrics;
}

Expand Down

0 comments on commit ad7bf51

Please sign in to comment.