Skip to content
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

Newer version and less round-trip code #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 0 additions & 29 deletions source/Plugins/GoogleAnalyticsV3/Field.cs

This file was deleted.

178 changes: 89 additions & 89 deletions source/Plugins/GoogleAnalyticsV3/Fields.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Expand All @@ -18,91 +18,91 @@ limitations under the License.
using System.Collections;

/*
Available fields to use with SetOnTracker(Field fieldName, object value)
*/
public class Fields {

//General
public readonly static Field ANONYMIZE_IP = new Field("&aip");
public readonly static Field HIT_TYPE = new Field("&t");
public readonly static Field SESSION_CONTROL = new Field("&sc");

public readonly static Field SCREEN_NAME = new Field("&cd");
public readonly static Field LOCATION = new Field("&dl");
public readonly static Field REFERRER = new Field("&dr");
public readonly static Field PAGE = new Field("&dp");
public readonly static Field HOSTNAME = new Field("&dh");
public readonly static Field TITLE = new Field("&dt");
public readonly static Field LANGUAGE = new Field("&ul");
public readonly static Field ENCODING = new Field("&de");

// System
public readonly static Field SCREEN_COLORS = new Field("&sd");
public readonly static Field SCREEN_RESOLUTION = new Field("&sr");
public readonly static Field VIEWPORT_SIZE = new Field("&vp");

// Application
public readonly static Field APP_NAME = new Field("&an");
public readonly static Field APP_ID = new Field("&aid");
public readonly static Field APP_INSTALLER_ID = new Field("&aiid");
public readonly static Field APP_VERSION = new Field("&av");

// Visitor
public readonly static Field CLIENT_ID = new Field("&cid");
public readonly static Field USER_ID = new Field("&uid");

// Campaign related fields; used in all hits.
public readonly static Field CAMPAIGN_NAME = new Field("&cn");
public readonly static Field CAMPAIGN_SOURCE = new Field("&cs");
public readonly static Field CAMPAIGN_MEDIUM = new Field("&cm");
public readonly static Field CAMPAIGN_KEYWORD = new Field("&ck");
public readonly static Field CAMPAIGN_CONTENT = new Field("&cc");
public readonly static Field CAMPAIGN_ID = new Field("&ci");
// Autopopulated campaign fields
public readonly static Field GCLID = new Field("&gclid");
public readonly static Field DCLID = new Field("&dclid");


// Event Hit (&t=event)
public readonly static Field EVENT_CATEGORY = new Field("&ec");
public readonly static Field EVENT_ACTION = new Field("&ea");
public readonly static Field EVENT_LABEL = new Field("&el");
public readonly static Field EVENT_VALUE = new Field("&ev");

// Social Hit (&t=social)
public readonly static Field SOCIAL_NETWORK = new Field("&sn");
public readonly static Field SOCIAL_ACTION = new Field("&sa");
public readonly static Field SOCIAL_TARGET = new Field("&st");

// Timing Hit (&t=timing)
public readonly static Field TIMING_VAR = new Field("&utv");
public readonly static Field TIMING_VALUE = new Field("&utt");
public readonly static Field TIMING_CATEGORY = new Field("&utc");
public readonly static Field TIMING_LABEL = new Field("&utl");


// Exception Hit (&t=exception)
public readonly static Field EX_DESCRIPTION = new Field("&exd");
public readonly static Field EX_FATAL = new Field("&exf");

// Ecommerce (&t=transaction / &t=item)
public readonly static Field CURRENCY_CODE = new Field("&cu");
public readonly static Field TRANSACTION_ID = new Field("&ti");
public readonly static Field TRANSACTION_AFFILIATION = new Field("&ta");
public readonly static Field TRANSACTION_SHIPPING = new Field("&ts");
public readonly static Field TRANSACTION_TAX = new Field("&tt");
public readonly static Field TRANSACTION_REVENUE = new Field("&tr");
public readonly static Field ITEM_SKU = new Field("&ic");
public readonly static Field ITEM_NAME = new Field("&in");
public readonly static Field ITEM_CATEGORY = new Field("&iv");
public readonly static Field ITEM_PRICE = new Field("&ip");
public readonly static Field ITEM_QUANTITY = new Field("&iq");

// General Configuration
public readonly static Field TRACKING_ID = new Field("&tid");
public readonly static Field SAMPLE_RATE = new Field("&sf");
public readonly static Field DEVELOPER_ID = new Field("&did");

public readonly static Field CUSTOM_METRIC = new Field("&cm");
public readonly static Field CUSTOM_DIMENSION = new Field("&cd");
}
Available strings to use with SetOnTracker(string stringName, object value)
*/
public class Fields
{
//General
public const string ANONYMIZE_IP = "&aip";
public const string HIT_TYPE = "&t";
public const string SESSION_CONTROL = "&sc";
public const string SCREEN_NAME = "&cd";
public const string LOCATION = "&dl";
public const string REFERRER = "&dr";
public const string PAGE = "&dp";
public const string HOSTNAME = "&dh";
public const string TITLE = "&dt";
public const string LANGUAGE = "&ul";
public const string ENCODING = "&de";
// System
public const string SCREEN_COLORS = "&sd";
public const string SCREEN_RESOLUTION = "&sr";
public const string VIEWPORT_SIZE = "&vp";
// Application
public const string APP_NAME = "&an";
public const string APP_ID = "&aid";
public const string APP_INSTALLER_ID = "&aiid";
public const string APP_VERSION = "&av";
// Visitor
public const string CLIENT_ID = "&cid";
public const string USER_ID = "&uid";
// Campaign related strings; used in all hits.
public const string CAMPAIGN_NAME = "&cn";
public const string CAMPAIGN_SOURCE = "&cs";
public const string CAMPAIGN_MEDIUM = "&cm";
public const string CAMPAIGN_KEYWORD = "&ck";
public const string CAMPAIGN_CONTENT = "&cc";
public const string CAMPAIGN_ID = "&ci";
// Autopopulated campaign strings
public const string GCLID = "&gclid";
public const string DCLID = "&dclid";
// Event Hit (&t=event)
public const string EVENT_CATEGORY = "&ec";
public const string EVENT_ACTION = "&ea";
public const string EVENT_LABEL = "&el";
public const string EVENT_VALUE = "&ev";
// Social Hit (&t=social)
public const string SOCIAL_NETWORK = "&sn";
public const string SOCIAL_ACTION = "&sa";
public const string SOCIAL_TARGET = "&st";
// Timing Hit (&t=timing)
public const string TIMING_VAR = "&utv";
public const string TIMING_VALUE = "&utt";
public const string TIMING_CATEGORY = "&utc";
public const string TIMING_LABEL = "&utl";
// Exception Hit (&t=exception)
public const string EX_DESCRIPTION = "&exd";
public const string EX_FATAL = "&exf";
// Ecommerce (&t=transaction / &t=item)
public const string CURRENCY_CODE = "&cu";
public const string TRANSACTION_ID = "&ti";
public const string TRANSACTION_AFFILIATION = "&ta";
public const string TRANSACTION_SHIPPING = "&ts";
public const string TRANSACTION_TAX = "&tt";
public const string TRANSACTION_REVENUE = "&tr";
public const string ITEM_SKU = "&ic";
public const string ITEM_NAME = "&in";
public const string ITEM_CATEGORY = "&iv";
public const string ITEM_PRICE = "&ip";
public const string ITEM_QUANTITY = "&iq";
// General Configuration
public const string TRACKING_ID = "&tid";
public const string SAMPLE_RATE = "&sf";
public const string DEVELOPER_ID = "&did";
public const string CUSTOM_METRIC = "&cm";
public const string CUSTOM_DIMENSION = "&cd";
}
12 changes: 6 additions & 6 deletions source/Plugins/GoogleAnalyticsV3/GAIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
Wrapper for Objective-C iOS SDK
*/
public class GAIHandler {
#if UNITY_IPHONE && !UNITY_EDITOR
#if UNITY_IPHONE
[DllImport("__Internal")]
private static extern void setOptOut(bool optOut);
public void _setOptOut(bool optOut){
Expand Down Expand Up @@ -179,25 +179,25 @@ public void _sendTiming(TimingHitBuilder builder){

[DllImport("__Internal")]
private static extern void addCustomDimensionToDictionary(int key, string value);
public void _buildCustomDimensionsDictionary<T>(HitBuilder<T> builder){
foreach(KeyValuePair<int, string> entry in builder.GetCustomDimensions())
public void _buildCustomDimensionsDictionary(HitBuilder builder){
foreach(var entry in builder.GetCustomDimensions())
{
addCustomDimensionToDictionary(entry.Key, entry.Value);
}
}

[DllImport("__Internal")]
private static extern void addCustomMetricToDictionary(int key, string value);
public void _buildCustomMetricsDictionary<T>(HitBuilder<T> builder){
foreach(KeyValuePair<int, string> entry in builder.GetCustomMetrics())
public void _buildCustomMetricsDictionary(HitBuilder builder){
foreach(var entry in builder.GetCustomMetrics())
{
addCustomMetricToDictionary(entry.Key, entry.Value);
}
}

[DllImport("__Internal")]
private static extern void buildCampaignParametersDictionary(string source, string medium, string name, string content, string keyword);
public void _buildCampaignParametersDictionary<T>(HitBuilder<T> builder){
public void _buildCampaignParametersDictionary(HitBuilder builder){
if(!String.IsNullOrEmpty(builder.GetCampaignSource())){
buildCampaignParametersDictionary(builder.GetCampaignSource(),
builder.GetCampaignMedium() != null ? builder.GetCampaignMedium() : "",
Expand Down
Binary file removed source/Plugins/GoogleAnalyticsV3/GAv3.prefab
Binary file not shown.
35 changes: 14 additions & 21 deletions source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsAndroidV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
appropriate methods in this class if the application is built for Android.
*/
public class GoogleAnalyticsAndroidV3 : IDisposable {
#if UNITY_ANDROID && !UNITY_EDITOR
#if UNITY_ANDROID
private string trackingCode;
private string appVersion;
private string appName;
Expand Down Expand Up @@ -84,7 +84,7 @@ internal void InitializeTracker() {
}
}

internal void SetTrackerVal(Field fieldName, object value) {
internal void SetTrackerVal(string fieldName,object value) {
object[] args = new object[] { fieldName.ToString(), value };
tracker.Call(GoogleAnalyticsV3.SET, args);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ private AndroidJavaObject BuildMap(string methodName, object[] simpleArgs,
hashMap.GetRawClass(), "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
object[] args = new object[2];
foreach (KeyValuePair<AndroidJavaObject, string> kvp in parameters) {
foreach (var kvp in parameters) {
using (AndroidJavaObject k = kvp.Key) {
using (AndroidJavaObject v = new AndroidJavaObject(
"java.lang.String", kvp.Value)) {
Expand Down Expand Up @@ -206,17 +206,16 @@ private AndroidJavaObject BuildMap(string methodName, object[] simpleArgs,
}
}

private Dictionary<AndroidJavaObject, string>
AddCustomVariablesAndCampaignParameters<T>(HitBuilder<T> builder) {
private Dictionary<AndroidJavaObject,string> AddCustomVariablesAndCampaignParameters(HitBuilder builder) {
Dictionary<AndroidJavaObject, string> parameters =
new Dictionary<AndroidJavaObject, string>();
AndroidJavaObject fieldName;
foreach (KeyValuePair<int, string> entry in builder.GetCustomDimensions()) {
foreach (var entry in builder.GetCustomDimensions()) {
fieldName = analyticsTrackingFields.CallStatic<AndroidJavaObject>(
"customDimension", entry.Key);
parameters.Add(fieldName, entry.Value);
}
foreach (KeyValuePair<int, string> entry in builder.GetCustomMetrics()) {
foreach (var entry in builder.GetCustomMetrics()) {
fieldName = analyticsTrackingFields.CallStatic<AndroidJavaObject>(
"customMetric", entry.Key);
parameters.Add(fieldName, entry.Value);
Expand Down Expand Up @@ -283,8 +282,7 @@ internal void LogScreen (AppViewHitBuilder builder) {
tracker.Call (GoogleAnalyticsV3.SET, args);
}

Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
object map = BuildMap(GoogleAnalyticsV3.APP_VIEW, parameters);
tracker.Call(GoogleAnalyticsV3.SEND, map);
Expand All @@ -304,8 +302,7 @@ internal void LogEvent(EventHitBuilder builder) {
args[3] = valueObj;

object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
map = BuildMap(GoogleAnalyticsV3.EVENT_HIT, args, parameters);
} else {
Expand Down Expand Up @@ -336,8 +333,7 @@ internal void LogTransaction(TransactionHitBuilder builder) {
args[5] = builder.GetCurrencyCode();
}
object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null){
map = BuildMap(GoogleAnalyticsV3.TRANSACTION_HIT, args, parameters);
} else {
Expand All @@ -362,8 +358,7 @@ internal void LogItem(ItemHitBuilder builder) {
args[5] = new AndroidJavaObject("java.lang.Long", builder.GetQuantity());

object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
map = BuildMap(GoogleAnalyticsV3.ITEM_HIT, args, parameters);
} else {
Expand All @@ -377,8 +372,7 @@ public void LogException(ExceptionHitBuilder builder) {
args[0] = builder.GetExceptionDescription();
args[1] = new AndroidJavaObject("java.lang.Boolean", builder.IsFatal());
object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
map = BuildMap(GoogleAnalyticsV3.EXCEPTION_HIT, args, parameters);
} else {
Expand All @@ -398,8 +392,7 @@ public void LogSocial(SocialHitBuilder builder) {
args[2] = builder.GetSocialTarget();

object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
map = BuildMap(GoogleAnalyticsV3.SOCIAL_HIT, args, parameters);
} else {
Expand All @@ -417,8 +410,7 @@ public void LogTiming(TimingHitBuilder builder) {
args[2] = builder.GetTimingName();
args[3] = builder.GetTimingLabel();
object map;
Dictionary<AndroidJavaObject, string> parameters =
AddCustomVariablesAndCampaignParameters(builder);
Dictionary<AndroidJavaObject, string> parameters = AddCustomVariablesAndCampaignParameters(builder);
if (parameters != null) {
map = BuildMap(GoogleAnalyticsV3.TIMING_HIT, args, parameters);
} else {
Expand Down Expand Up @@ -465,6 +457,7 @@ public void SetDryRun(bool dryRun) {
}

#endif

public void Dispose()
{
#if UNITY_ANDROID && !UNITY_EDITOR
Expand Down
Loading