diff --git a/src/GoogleMeasurementProtocol_NetStandard/GoogleAnalyticsMeasurementProtocol_NetStandard.csproj b/src/GoogleMeasurementProtocol_NetStandard/GoogleAnalyticsMeasurementProtocol_NetStandard.csproj
index 0ec9f04..25d24e3 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/GoogleAnalyticsMeasurementProtocol_NetStandard.csproj
+++ b/src/GoogleMeasurementProtocol_NetStandard/GoogleAnalyticsMeasurementProtocol_NetStandard.csproj
@@ -5,7 +5,7 @@
GoogleMeasurementProtocol
GoogleMeasurementProtocol
GoogleMeasurementProtocol
- 2.1.0
+ 2.2.0
Ion Sapoval
Ion Sapoval
Google Measurement Protocol
@@ -15,8 +15,9 @@ This library provides support for creating any type of Measurement Protocol requ
https://github.com/ion-sapoval/google-measurement-protocol-dotnet
MeasurementProtocol Google GoogleMeasurementProtocol Analytics
- - Added possibility to inject HttpClient
-- Async actions are no longer dependent on captured context.
+ - Added support for Disabling Advertising Personalization parameter
+- Added parameterless overload for PostAsync and GetAsync from request level
+- Fixes and improvements
true
true
Key.snk
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Parameters/General/DisablingAdvertisingPersonalization.cs b/src/GoogleMeasurementProtocol_NetStandard/Parameters/General/DisablingAdvertisingPersonalization.cs
new file mode 100644
index 0000000..99e8f53
--- /dev/null
+++ b/src/GoogleMeasurementProtocol_NetStandard/Parameters/General/DisablingAdvertisingPersonalization.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace GoogleMeasurementProtocol.Parameters.General
+{
+ public class DisablingAdvertisingPersonalization : Parameter
+ {
+ ///
+ /// Use this parameter to mark an event as disabled for advertising personalization,
+ /// including for events from a property with a setting that otherwise permits ads personalization.
+ /// For example, if a transaction is marked to disable advertising personalization,
+ /// it won't be used when populating a remarketing audience for "past purchasers".
+ ///
+ public DisablingAdvertisingPersonalization(bool value) : base(value)
+ {
+ }
+
+ public override string Name => "npa";
+
+ public override Type ValueType => typeof(bool);
+ }
+}
+
\ No newline at end of file
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs
index 2f335a1..ad10562 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs
@@ -54,7 +54,7 @@ private void ValidateRequestParams()
{
RequiredParamsValidator.Validate(_requests[i].Parameters);
- CompatibilityValidator.Validate(_requests[i].Parameters, _requests[i],_requests[i].HitType);
+ CompatibilityValidator.Validate(_requests[i]);
}
catch (Exception ex)
{
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/DebugRequest.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/DebugRequest.cs
index 564407b..dd7f2e8 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/DebugRequest.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/DebugRequest.cs
@@ -21,6 +21,11 @@ public async Task PostAsync(ClientId clientId)
return JsonConvert.DeserializeObject(response);
}
+ public async Task PostAsync()
+ {
+ return await PostAsync((ClientId)null);
+ }
+
public async Task PostAsync(UserId userId)
{
var response =
@@ -37,6 +42,11 @@ public async Task GetAsync(ClientId clientId)
return JsonConvert.DeserializeObject(response);
}
+ public async Task GetAsync()
+ {
+ return await GetAsync((ClientId)null);
+ }
+
public async Task GetAsync(UserId userId)
{
var response =
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/IDebugRequest.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/IDebugRequest.cs
index 0e43a7c..92b2743 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/IDebugRequest.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/Debug/IDebugRequest.cs
@@ -15,6 +15,15 @@ public interface IDebugRequest
/// If a hit is valid, parserMessage will be an empty array.
Task PostAsync(ClientId clientId);
+ ///
+ /// Makes an async Post request to Google Analytics Hit Validation
+ ///
+ /// The response root, hitParsingResult, is an array whose length will correspond to the number of hits sent in the original request.
+ /// Each object in the array will contain the keys valid, hit, and parserMessage.
+ /// If a hit is invalid, parserMessage will contain an array of objects describing the validation issues.
+ /// If a hit is valid, parserMessage will be an empty array.
+ Task PostAsync();
+
///
/// Makes an async Post request to Google Analytics
///
@@ -35,6 +44,15 @@ public interface IDebugRequest
/// If a hit is valid, parserMessage will be an empty array.
Task GetAsync(ClientId clientId);
+ ///
+ /// Makes an async Get request to Google Analytics Hit Validation
+ ///
+ /// The response root, hitParsingResult, is an array whose length will correspond to the number of hits sent in the original request.
+ /// Each object in the array will contain the keys valid, hit, and parserMessage.
+ /// If a hit is invalid, parserMessage will contain an array of objects describing the validation issues.
+ /// If a hit is valid, parserMessage will be an empty array.
+ Task GetAsync();
+
///
/// Makes an async Get request to Google Analytics Hit Validation
///
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/IGoogleAnalyticsRequest.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/IGoogleAnalyticsRequest.cs
index 916440c..6dd1b78 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Requests/IGoogleAnalyticsRequest.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/IGoogleAnalyticsRequest.cs
@@ -18,6 +18,11 @@ public interface IGoogleAnalyticsRequest
/// Anonymously identifies a particular user, device, or browser instance
Task PostAsync(ClientId clientId);
+ ///
+ /// Makes an async Post request to Google Analytics
+ ///
+ Task PostAsync();
+
///
/// Makes an async Post request to Google Analytics
///
@@ -30,6 +35,11 @@ public interface IGoogleAnalyticsRequest
/// Anonymously identifies a particular user, device, or browser instance
Task GetAsync(ClientId clientId);
+ ///
+ /// Makes an async Get request to Google Analytics
+ ///
+ Task GetAsync();
+
///
/// Makes an async Get request to Google Analytics
///
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs
index 67c30f5..e70610e 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs
@@ -54,6 +54,11 @@ public virtual async Task PostAsync(ClientId clientId)
await PostAsync(clientId, GoogleEndpointAddresses.Collect);
}
+ public virtual async Task PostAsync()
+ {
+ await PostAsync((ClientId)null);
+ }
+
internal async Task PostAsync(UserId userId, string url)
{
CheckAndAddUserId(userId);
@@ -80,6 +85,11 @@ public virtual async Task GetAsync(ClientId clientId)
await GetAsync(clientId, GoogleEndpointAddresses.Collect);
}
+ public virtual async Task GetAsync()
+ {
+ await GetAsync((ClientId)null);
+ }
+
internal async Task GetAsync(UserId userId, string url)
{
CheckAndAddUserId(userId);
@@ -98,7 +108,7 @@ protected virtual void ValidateRequestParams()
{
RequiredParamsValidator.Validate(Parameters);
- CompatibilityValidator.Validate(Parameters, this, HitType);
+ CompatibilityValidator.Validate(this);
}
internal void CheckAndAddUserId(UserId userId)
@@ -116,7 +126,12 @@ internal void CheckAndAddUserId(UserId userId)
internal void CheckAndAddClientId(ClientId clientId)
{
- if (clientId?.Value == null)
+ if (clientId == null)
+ {
+ return;
+ }
+
+ if (clientId.Value == null)
{
throw new ArgumentNullException(nameof(clientId));
}
diff --git a/src/GoogleMeasurementProtocol_NetStandard/Validators/CompatibilityValidator.cs b/src/GoogleMeasurementProtocol_NetStandard/Validators/CompatibilityValidator.cs
index 54adf84..8e5f7d2 100644
--- a/src/GoogleMeasurementProtocol_NetStandard/Validators/CompatibilityValidator.cs
+++ b/src/GoogleMeasurementProtocol_NetStandard/Validators/CompatibilityValidator.cs
@@ -1,17 +1,15 @@
using System;
-using System.Collections.Generic;
-using GoogleMeasurementProtocol.Parameters;
using GoogleMeasurementProtocol.Requests;
namespace GoogleMeasurementProtocol.Validators
{
public static class CompatibilityValidator
{
- public static void Validate(List parameters, RequestBase request, string hitType)
+ public static void Validate(RequestBase request)
{
- foreach (var param in parameters)
+ foreach (var param in request.Parameters)
{
- if (param.SupportedHitTypes != null && !param.SupportedHitTypes.Exists(h => h.Equals(hitType)))
+ if (param.SupportedHitTypes != null && !param.SupportedHitTypes.Exists(h => h.Equals(request.HitType)))
{
throw new ApplicationException($"Parameters of type '{param.GetType().Name}' are not supported by requests of type {request.GetType().Name}");
}
diff --git a/src/TestConsole/Program.cs b/src/TestConsole/Program.cs
index c676d3f..2f1a677 100644
--- a/src/TestConsole/Program.cs
+++ b/src/TestConsole/Program.cs
@@ -3,6 +3,7 @@
using System.Net.Http;
using GoogleMeasurementProtocol;
using GoogleMeasurementProtocol.Parameters.ContentInformation;
+using GoogleMeasurementProtocol.Parameters.General;
using GoogleMeasurementProtocol.Parameters.User;
using GoogleMeasurementProtocol.Requests;
@@ -12,14 +13,16 @@ class Program
{
static void Main(string[] args)
{
- var factory = new GoogleAnalyticsRequestFactory("UA-104485591-1", new HttpClient());
+ var factory = new GoogleAnalyticsRequestFactory("UA-xxxxxx-x", new HttpClient());
var request1 = factory.CreateRequest(HitTypes.PageView);
request1.Parameters.Add(new DocumentHostName("test55.com"));
request1.Parameters.Add(new DocumentPath("/test/testPath6"));
request1.Parameters.Add(new DocumentTitle("test title2"));
- request1.Parameters.Add(new UserId(Guid.NewGuid().ToString()));
+ request1.Parameters.Add(new ClientId(Guid.NewGuid()));
+ //request1.Parameters.Add(new UserId(Guid.NewGuid().ToString()));
+ request1.Parameters.Add(new DisablingAdvertisingPersonalization(true));
var request2 = factory.CreateRequest(HitTypes.PageView);
@@ -28,15 +31,18 @@ static void Main(string[] args)
request2.Parameters.Add(new DocumentTitle("test title5"));
request2.Parameters.Add(new ClientId(Guid.NewGuid().ToString()));
- request1.GetAsync(new ClientId(Guid.NewGuid())).Wait();
- request1.PostAsync(new UserId(Guid.NewGuid().ToString())).Wait();
+ request1.GetAsync().Wait();
+ request1.PostAsync().Wait();
- var batchRequest =
+ //request1.GetAsync(new ClientId(Guid.NewGuid())).Wait();
+ //request1.PostAsync(new UserId(Guid.NewGuid().ToString())).Wait();
+
+ var batchRequest =
factory.CreateBatchRequest(new List { request1, request2 });
batchRequest.PostAsync().Wait();
- var requestValidationResponse = request1.Debug.PostAsync(new UserId("userId")).Result;
+ var requestValidationResponse = request1.Debug.PostAsync().Result;
Console.Write("Done!");
Console.ReadKey();
diff --git a/src/TestConsole/TestConsole.csproj b/src/TestConsole/TestConsole.csproj
index 17e0962..13b06cd 100644
--- a/src/TestConsole/TestConsole.csproj
+++ b/src/TestConsole/TestConsole.csproj
@@ -34,8 +34,8 @@
4
-
- ..\packages\GoogleMeasurementProtocol.2.1.0\lib\netstandard2.0\GoogleMeasurementProtocol.dll
+
+ ..\packages\GoogleMeasurementProtocol.2.2.0\lib\netstandard2.0\GoogleMeasurementProtocol.dll
..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll
diff --git a/src/TestConsole/packages.config b/src/TestConsole/packages.config
index 997e5df..45f30dd 100644
--- a/src/TestConsole/packages.config
+++ b/src/TestConsole/packages.config
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/src/UnitTests/Test_ParameterDefinitions/ParameterTypeConsistency.cs b/src/UnitTests/Test_ParameterDefinitions/ParameterTypeConsistency.cs
index a738229..79d4918 100644
--- a/src/UnitTests/Test_ParameterDefinitions/ParameterTypeConsistency.cs
+++ b/src/UnitTests/Test_ParameterDefinitions/ParameterTypeConsistency.cs
@@ -1,10 +1,8 @@
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
-using System.Threading.Tasks;
using GoogleMeasurementProtocol.Parameters;
using GoogleMeasurementProtocol.Parameters.Hit;
using Microsoft.VisualStudio.TestTools.UnitTesting;