From b519e4e0b726741b3f4c14b2058baf771b074a97 Mon Sep 17 00:00:00 2001 From: Emmanuelle Date: Tue, 5 Aug 2014 16:58:30 -0700 Subject: [PATCH] Builder files For building complex hit types. --- .../HitBuilders/AppViewHitBuilder.cs | 48 ++++++ .../HitBuilders/EventHitBuilder.cs | 86 ++++++++++ .../HitBuilders/ExceptionHitBuilder.cs | 54 +++++++ .../HitBuilders/HitBuilder.cs | 150 ++++++++++++++++++ .../HitBuilders/ItemHitBuilder.cs | 130 +++++++++++++++ .../HitBuilders/SocialHitBuilder.cs | 80 ++++++++++ .../HitBuilders/TimingHitBuilder.cs | 84 ++++++++++ .../HitBuilders/TransactionHitBuilder.cs | 115 ++++++++++++++ 8 files changed, 747 insertions(+) create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/AppViewHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/EventHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/ExceptionHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/HitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/ItemHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/SocialHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/TimingHitBuilder.cs create mode 100644 source/Plugins/GoogleAnalyticsV3/HitBuilders/TransactionHitBuilder.cs diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/AppViewHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/AppViewHitBuilder.cs new file mode 100644 index 0000000..eff37e3 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/AppViewHitBuilder.cs @@ -0,0 +1,48 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class AppViewHitBuilder : HitBuilder { + + private string screenName = ""; + + public string GetScreenName() { + return screenName; + } + + public AppViewHitBuilder SetScreenName(string screenName) { + if (screenName != null) { + this.screenName = screenName; + } + return this; + } + + public override AppViewHitBuilder GetThis() { + return this; + } + + public override AppViewHitBuilder Validate() { + if (String.IsNullOrEmpty(screenName)) { + Debug.Log("No screen name provided - App View hit cannot be sent."); + return null; + } + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/EventHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/EventHitBuilder.cs new file mode 100644 index 0000000..9c978b3 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/EventHitBuilder.cs @@ -0,0 +1,86 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class EventHitBuilder : HitBuilder { + + private string eventCategory = ""; + private string eventAction = ""; + private string eventLabel = ""; + private long eventValue; + + public string GetEventCategory() { + return eventCategory; + } + + public EventHitBuilder SetEventCategory(string eventCategory) { + if (eventCategory != null) { + this.eventCategory = eventCategory; + } + return this; + } + + public string GetEventAction() { + return eventAction; + } + + public EventHitBuilder SetEventAction(string eventAction) { + if (eventAction != null) { + this.eventAction = eventAction; + } + return this; + } + + public string GetEventLabel() { + return eventLabel; + } + + public EventHitBuilder SetEventLabel(string eventLabel) { + if (eventLabel != null) { + this.eventLabel = eventLabel; + } + return this; + } + + public long GetEventValue() { + return eventValue; + } + + public EventHitBuilder SetEventValue(long eventValue) { + this.eventValue = eventValue; + return this; + } + + public override EventHitBuilder GetThis() { + return this; + } + + public override EventHitBuilder Validate() { + if (String.IsNullOrEmpty(eventCategory)) { + Debug.LogWarning("No event category provided - Event hit cannot be sent."); + return null; + } + if (String.IsNullOrEmpty(eventAction)) { + Debug.LogWarning("No event action provided - Event hit cannot be sent."); + return null; + } + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/ExceptionHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/ExceptionHitBuilder.cs new file mode 100644 index 0000000..36f2e8d --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/ExceptionHitBuilder.cs @@ -0,0 +1,54 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class ExceptionHitBuilder : HitBuilder { + + private string exceptionDescription = ""; + private bool fatal = false; + + public string GetExceptionDescription(){ + return exceptionDescription; + } + + public ExceptionHitBuilder SetExceptionDescription(string exceptionDescription) { + if(exceptionDescription != null){ + this.exceptionDescription = exceptionDescription; + } + return this; + } + + public bool IsFatal(){ + return fatal; + } + + public ExceptionHitBuilder SetFatal(bool fatal) { + this.fatal = fatal; + return this; + } + + public override ExceptionHitBuilder GetThis(){ + return this; + } + + public override ExceptionHitBuilder Validate(){ + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/HitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/HitBuilder.cs new file mode 100644 index 0000000..0fde4c5 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/HitBuilder.cs @@ -0,0 +1,150 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +/* + Base class for building hits. This class stores data which can be sent with + any hit type but cannot be sent independent of other hits. + */ +public abstract class HitBuilder { + + private Dictionary customDimensions = + new Dictionary(); + private Dictionary customMetrics = new Dictionary(); + + private string campaignName = ""; + private string campaignSource = ""; + private string campaignMedium = ""; + private string campaignKeyword = ""; + private string campaignContent = ""; + private string campaignID = ""; + private string gclid = ""; + private string dclid = ""; + + public abstract T GetThis(); + public abstract T Validate(); + + public T SetCustomDimension(int dimensionNumber, string value) { + customDimensions.Add(dimensionNumber, value); + return GetThis(); + } + + public Dictionary GetCustomDimensions() { + return customDimensions; + } + + public T SetCustomMetric(int metricNumber, string value) { + customMetrics.Add(metricNumber, value); + return GetThis(); + } + + public Dictionary GetCustomMetrics() { + return customMetrics; + } + + public string GetCampaignName() { + return campaignName; + } + + public T SetCampaignName(string campaignName) { + if (campaignName != null) { + this.campaignName = campaignName; + } + return GetThis(); + } + + public string GetCampaignSource() { + return campaignSource; + } + + public T SetCampaignSource(string campaignSource) { + if (campaignSource != null) { + this.campaignSource = campaignSource; + } else { + Debug.Log("Campaign source cannot be null or empty"); + } + return GetThis(); + } + + public string GetCampaignMedium() { + return campaignMedium; + } + + public T SetCampaignMedium(string campaignMedium) { + if (campaignMedium != null) { + this.campaignMedium = campaignMedium; + } + return GetThis(); + } + + public string GetCampaignKeyword() { + return campaignKeyword; + } + + public T SetCampaignKeyword(string campaignKeyword) { + if (campaignKeyword != null) { + this.campaignKeyword = campaignKeyword; + } + return GetThis(); + } + + public string GetCampaignContent() { + return campaignContent; + } + + public T SetCampaignContent(string campaignContent) { + if (campaignContent != null) { + this.campaignContent = campaignContent; + } + return GetThis(); + } + + public string GetCampaignID() { + return campaignID; + } + + public T SetCampaignID(string campaignID) { + if (campaignID != null) { + this.campaignID = campaignID; + } + return GetThis(); + } + + public string GetGclid() { + return gclid; + } + + public T SetGclid(string gclid) { + if (gclid != null) { + this.gclid = gclid; + } + return GetThis(); + } + + public string GetDclid() { + return dclid; + } + + public T SetDclid(string dclid) { + if (dclid != null) { + this.dclid = dclid; + } + return GetThis(); + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/ItemHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/ItemHitBuilder.cs new file mode 100644 index 0000000..d2c04f8 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/ItemHitBuilder.cs @@ -0,0 +1,130 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class ItemHitBuilder : HitBuilder { + + private string transactionID = ""; + private string name = ""; + private string SKU = ""; + private double price; + private string category = ""; + private long quantity; + private string currencyCode = ""; + + public string GetTransactionID() { + return transactionID; + } + + public ItemHitBuilder SetTransactionID(string transactionID) { + if(transactionID != null){ + this.transactionID = transactionID; + } + return this; + } + + public string GetName() { + return name; + } + + public ItemHitBuilder SetName(string name) { + if(name != null){ + this.name = name; + } + return this; + } + + public string GetSKU() { + return name; + } + + public ItemHitBuilder SetSKU(string SKU) { + if(SKU != null){ + this.SKU = SKU; + } + return this; + } + + public double GetPrice() { + return price; + } + + public ItemHitBuilder SetPrice(double price) { + this.price = price; + return this; + } + + public string GetCategory() { + return category; + } + + public ItemHitBuilder SetCategory(string category) { + if(category != null){ + this.category = category; + } + return this; + } + + public long GetQuantity() { + return quantity; + } + + public ItemHitBuilder SetQuantity(long quantity) { + this.quantity = quantity; + return this; + } + + public string GetCurrencyCode() { + return currencyCode; + } + + public ItemHitBuilder SetCurrencyCode(string currencyCode) { + if(currencyCode != null){ + this.currencyCode = currencyCode; + } + return this; + } + + public override ItemHitBuilder GetThis(){ + return this; + } + + public override ItemHitBuilder Validate(){ + if(String.IsNullOrEmpty(transactionID)){ + Debug.LogWarning("No transaction ID provided - Item hit cannot be sent."); + return null; + } + if(String.IsNullOrEmpty(name)){ + Debug.LogWarning("No name provided - Item hit cannot be sent."); + return null; + } + if(String.IsNullOrEmpty(SKU)){ + Debug.LogWarning("No SKU provided - Item hit cannot be sent."); + return null; + } + if(price == 0.0D){ + Debug.Log("Price in item hit is 0."); + } + if(quantity == 0L){ + Debug.Log("Quantity in item hit is 0."); + } + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/SocialHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/SocialHitBuilder.cs new file mode 100644 index 0000000..ef07407 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/SocialHitBuilder.cs @@ -0,0 +1,80 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class SocialHitBuilder : HitBuilder { + + private string socialNetwork = ""; + private string socialAction = ""; + private string socialTarget = ""; + + public string GetSocialNetwork(){ + return socialNetwork; + } + + public SocialHitBuilder SetSocialNetwork(string socialNetwork) { + if(socialNetwork != null){ + this.socialNetwork = socialNetwork; + } + return this; + } + + public string GetSocialAction(){ + return socialAction; + } + + public SocialHitBuilder SetSocialAction(string socialAction) { + if(socialAction != null){ + this.socialAction = socialAction; + } + return this; + } + + public string GetSocialTarget(){ + return socialTarget; + } + + public SocialHitBuilder SetSocialTarget(string socialTarget) { + if(socialTarget != null){ + this.socialTarget = socialTarget; + } + return this; + } + + public override SocialHitBuilder GetThis(){ + return this; + } + + public override SocialHitBuilder Validate(){ + if(String.IsNullOrEmpty(socialNetwork)){ + Debug.LogError("No social network provided - Social hit cannot be sent"); + return null; + } + if(String.IsNullOrEmpty(socialAction)){ + Debug.LogError("No social action provided - Social hit cannot be sent"); + return null; + } + if(String.IsNullOrEmpty(socialTarget)){ + Debug.LogError("No social target provided - Social hit cannot be sent"); + return null; + } + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/TimingHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/TimingHitBuilder.cs new file mode 100644 index 0000000..d8a05c1 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/TimingHitBuilder.cs @@ -0,0 +1,84 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections.Generic; +using System; + +public class TimingHitBuilder : HitBuilder { + + private string timingCategory = ""; + private long timingInterval; + private string timingName = ""; + private string timingLabel = ""; + + public string GetTimingCategory(){ + return timingCategory; + } + + public TimingHitBuilder SetTimingCategory(string timingCategory) { + if(timingCategory != null){ + this.timingCategory = timingCategory; + } + return this; + } + + public long GetTimingInterval(){ + return timingInterval; + } + + public TimingHitBuilder SetTimingInterval(long timingInterval) { + this.timingInterval = timingInterval; + return this; + } + + public string GetTimingName(){ + return timingName; + } + + public TimingHitBuilder SetTimingName(string timingName) { + if(timingName != null){ + this.timingName = timingName; + } + return this; + } + + public string GetTimingLabel(){ + return timingLabel; + } + + public TimingHitBuilder SetTimingLabel(string timingLabel) { + if(timingLabel != null){ + this.timingLabel = timingLabel; + } + return this; + } + + public override TimingHitBuilder GetThis(){ + return this; + } + + public override TimingHitBuilder Validate(){ + if(String.IsNullOrEmpty(timingCategory)){ + Debug.LogError("No timing category provided - Timing hit cannot be sent"); + return null; + } + if(timingInterval == 0L){ + Debug.Log("Interval in timing hit is 0."); + } + return this; + } +} diff --git a/source/Plugins/GoogleAnalyticsV3/HitBuilders/TransactionHitBuilder.cs b/source/Plugins/GoogleAnalyticsV3/HitBuilders/TransactionHitBuilder.cs new file mode 100644 index 0000000..80481e5 --- /dev/null +++ b/source/Plugins/GoogleAnalyticsV3/HitBuilders/TransactionHitBuilder.cs @@ -0,0 +1,115 @@ +/* + Copyright 2014 Google Inc. All rights reserved. + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class TransactionHitBuilder : HitBuilder { + + private string transactionID = ""; + private string affiliation = ""; + private double revenue; + private double tax; + private double shipping; + private string currencyCode = ""; + + public string GetTransactionID() { + return transactionID; + } + + public TransactionHitBuilder SetTransactionID(string transactionID) { + if(transactionID != null){ + this.transactionID = transactionID; + } + return this; + } + + public string GetAffiliation() { + return affiliation; + } + + public TransactionHitBuilder SetAffiliation(string affiliation) { + if(affiliation != null){ + this.affiliation = affiliation; + } + return this; + } + + public double GetRevenue() { + return revenue; + } + + public TransactionHitBuilder SetRevenue(double revenue) { + this.revenue = revenue; + return this; + } + + public double GetTax() { + return tax; + } + + public TransactionHitBuilder SetTax(double tax) { + this.tax = tax; + return this; + } + + public double GetShipping() { + return shipping; + } + + public TransactionHitBuilder SetShipping(double shipping) { + this.shipping = shipping; + return this; + } + + public string GetCurrencyCode() { + return currencyCode; + } + + public TransactionHitBuilder SetCurrencyCode(string currencyCode) { + if(currencyCode != null){ + this.currencyCode = currencyCode; + } + return this; + } + + public override TransactionHitBuilder GetThis(){ + return this; + } + + public override TransactionHitBuilder Validate(){ + if(String.IsNullOrEmpty(transactionID)){ + Debug.LogWarning("No transaction ID provided - Transaction hit cannot be sent."); + return null; + } + if(String.IsNullOrEmpty(affiliation)){ + Debug.LogWarning("No affiliation provided - Transaction hit cannot be sent."); + return null; + } + if(revenue == 0){ + Debug.Log("Revenue in transaction hit is 0."); + } + if(tax == 0){ + Debug.Log("Tax in transaction hit is 0."); + } + if(shipping == 0){ + Debug.Log("Shipping in transaction hit is 0."); + } + return this; + } +}