Skip to content

Commit ad7bf51

Browse files
authored
Merge pull request #152 from 96andrei/AndroidCustomData
Fixed Custom Dimensions and Custom Metrics on Android.
2 parents cc437f4 + ab171cb commit ad7bf51

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

source/Plugins/GoogleAnalyticsV4/GoogleAnalyticsAndroidV4.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ internal void LogEvent(EventHitBuilder builder) {
100100
eventBuilder.Call<AndroidJavaObject>("setAction", new object[] { builder.GetEventAction() });
101101
eventBuilder.Call<AndroidJavaObject>("setLabel", new object[] { builder.GetEventLabel() });
102102
eventBuilder.Call<AndroidJavaObject>("setValue", new object[] { builder.GetEventValue() });
103+
104+
foreach(KeyValuePair<int, string> i in builder.GetCustomDimensions())
105+
{
106+
eventBuilder.Call<AndroidJavaObject>("setCustomDimension", new object[] { i.Key, i.Value });
107+
}
108+
109+
foreach(KeyValuePair<int, float> i in builder.GetCustomMetrics())
110+
{
111+
eventBuilder.Call<AndroidJavaObject>("setCustomMetric", new object[] { i.Key, i.Value });
112+
}
113+
103114
object[] builtEvent = new object[] { eventBuilder.Call<AndroidJavaObject>("build") };
104115
tracker.Call("send", builtEvent);
105116
}

source/Plugins/GoogleAnalyticsV4/GoogleAnalyticsMPV3.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private string AddCustomVariables<T>(HitBuilder<T> builder) {
225225
WWW.EscapeURL(entry.Value.ToString());
226226
}
227227
}
228-
foreach(KeyValuePair<int, string> entry in builder.GetCustomMetrics())
228+
foreach(KeyValuePair<int, float> entry in builder.GetCustomMetrics())
229229
{
230230
if (entry.Value != null) {
231231
url += Fields.CUSTOM_METRIC.ToString() + entry.Key + "=" +

source/Plugins/GoogleAnalyticsV4/HitBuilders/HitBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class HitBuilder<T> {
2828

2929
private Dictionary<int, string> customDimensions =
3030
new Dictionary<int,string>();
31-
private Dictionary<int, string> customMetrics = new Dictionary<int,string>();
31+
private Dictionary<int, float> customMetrics = new Dictionary<int,float>();
3232

3333
private string campaignName = "";
3434
private string campaignSource = "";
@@ -51,12 +51,12 @@ public Dictionary<int, string> GetCustomDimensions() {
5151
return customDimensions;
5252
}
5353

54-
public T SetCustomMetric(int metricNumber, string value) {
54+
public T SetCustomMetric(int metricNumber, float value) {
5555
customMetrics.Add(metricNumber, value);
5656
return GetThis();
5757
}
5858

59-
public Dictionary<int, string> GetCustomMetrics() {
59+
public Dictionary<int, float> GetCustomMetrics() {
6060
return customMetrics;
6161
}
6262

0 commit comments

Comments
 (0)