Skip to content

Fixed Custom Dimensions and Custom Metrics on Android. #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ internal void LogEvent(EventHitBuilder builder) {
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 @@ private string AddCustomVariables<T>(HitBuilder<T> builder) {
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 Dictionary<int, string> GetCustomDimensions() {
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