-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added .Net Standard project version. Signed assembly with Strong Name.
- Loading branch information
1 parent
9683f33
commit af5af1a
Showing
142 changed files
with
3,253 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace GoogleMeasurementProtocol | ||
{ | ||
public static class HitTypes | ||
{ | ||
public const string PageView = "pageview"; | ||
|
||
public const string ScreenView = "screenview"; | ||
|
||
public const string Event = "event"; | ||
|
||
public const string Transaction = "transaction"; | ||
|
||
public const string Item = "item"; | ||
|
||
public const string Social = "social"; | ||
|
||
public const string Exception = "exception"; | ||
|
||
public const string Timing = "timing"; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/GoogleMeasurementProtocol_NetStandard/Extensions/ListExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Globalization; | ||
using GoogleMeasurementProtocol.Parameters; | ||
|
||
namespace GoogleMeasurementProtocol.Extensions | ||
{ | ||
public static class ListExtensions | ||
{ | ||
public static NameValueCollection GenerateNameValueCollection(this List<Parameter> list) | ||
{ | ||
var nameValueCollection = new NameValueCollection(); | ||
|
||
if (list == null) | ||
{ | ||
return nameValueCollection; | ||
} | ||
|
||
foreach (var param in list) | ||
{ | ||
switch (param.ValueType.Name) | ||
{ | ||
case "Boolean": | ||
|
||
nameValueCollection[param.Name] = param.Value == null ? string.Empty : (bool)param.Value ? "1" : "0"; | ||
break; | ||
|
||
case "Decimal": | ||
nameValueCollection[param.Name] = param.Value == null ? string.Empty : Convert.ToString(param.Value, CultureInfo.InvariantCulture); | ||
break; | ||
|
||
default: | ||
nameValueCollection[param.Name] = param.Value == null ? string.Empty : param.Value.ToString(); | ||
break; | ||
} | ||
} | ||
|
||
return nameValueCollection; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ogleMeasurementProtocol_NetStandard/GoogleAnalyticsMeasurementProtocol_NetStandard.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AssemblyName>GoogleMeasurementProtocol</AssemblyName> | ||
<RootNamespace>GoogleMeasurementProtocol</RootNamespace> | ||
<PackageId>GoogleMeasurementProtocol</PackageId> | ||
<Version>1.4.3</Version> | ||
<Authors>Ion Sapoval</Authors> | ||
<Company>Ion Sapoval</Company> | ||
<Description>.Net library for sending Google Analytics Measurement Protocol requests. | ||
This library provides support for creating any type of Measurement Protocol request by using any of the existing Measurement Protocol request parameters.</Description> | ||
<Copyright>Copyright (c) 2014</Copyright> | ||
<PackageLicenseUrl>https://github.com/ion-sapoval/google-measurement-protocol-dotnet/blob/master/LICENSE.TXT</PackageLicenseUrl> | ||
<PackageProjectUrl>https://github.com/ion-sapoval/google-measurement-protocol-dotnet</PackageProjectUrl> | ||
<PackageTags>MeasurementProtocol Google GoogleMeasurementProtocol Analytics</PackageTags> | ||
<PackageReleaseNotes>Signed assembly with a Strong Name. | ||
Converted to a .Net Standard library.</PackageReleaseNotes> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile> | ||
<DelaySign>false</DelaySign> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
117 changes: 117 additions & 0 deletions
117
src/GoogleMeasurementProtocol_NetStandard/GoogleAnalyticsRequestFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using GoogleMeasurementProtocol.Parameters; | ||
using GoogleMeasurementProtocol.Parameters.General; | ||
using GoogleMeasurementProtocol.Requests; | ||
|
||
|
||
namespace GoogleMeasurementProtocol | ||
{ | ||
public class GoogleAnalyticsRequestFactory | ||
{ | ||
private readonly IWebProxy _proxy; | ||
private readonly ProtocolVersion _protocolVersion = new ProtocolVersion("1"); | ||
private readonly TrackingId _trackingId; | ||
|
||
[Obsolete("Google is supporting now only https protocol. Parameter useSsl doesn't have any effect.")] | ||
public GoogleAnalyticsRequestFactory(TrackingId trackingId, bool useSslConnection, IWebProxy proxy = null) : this(trackingId, proxy) | ||
{ | ||
} | ||
|
||
[Obsolete("Google is supporting now only https protocol. Parameter useSsl doesn't have any effect.")] | ||
public GoogleAnalyticsRequestFactory(string trackingId, bool useSslConnection, IWebProxy proxy = null) : this(trackingId, proxy) | ||
{ | ||
} | ||
|
||
public GoogleAnalyticsRequestFactory(TrackingId trackingId, IWebProxy proxy = null) | ||
{ | ||
if (trackingId?.Value == null) | ||
{ | ||
throw new ArgumentException("TrackingId can't be null or empty.", nameof(trackingId)); | ||
} | ||
|
||
_trackingId = trackingId; | ||
_proxy = proxy; | ||
} | ||
|
||
public GoogleAnalyticsRequestFactory(string trackingId, IWebProxy proxy = null) | ||
{ | ||
if (string.IsNullOrEmpty(trackingId)) | ||
{ | ||
throw new ArgumentException("TrackingId can't be null or empty.", nameof(trackingId)); | ||
} | ||
|
||
_trackingId = new TrackingId(trackingId); | ||
_proxy = proxy; | ||
} | ||
|
||
|
||
public IGoogleAnalyticsRequest CreateRequest(string hitType, IEnumerable<Parameter> requestParameters = null) | ||
{ | ||
if (hitType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(hitType)); | ||
} | ||
|
||
IGoogleAnalyticsRequest request; | ||
|
||
switch (hitType.ToLower()) | ||
{ | ||
case HitTypes.PageView: | ||
|
||
request = new PageViewRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Event: | ||
|
||
request = new EventRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Exception: | ||
|
||
request = new ExceptionTrackingRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Item: | ||
|
||
request = new ItemRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.ScreenView: | ||
|
||
request = new ScreenTrackingRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Social: | ||
|
||
request = new SocialInteractionsRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Timing: | ||
|
||
request = new UserTimingTrackingRequest(_proxy); | ||
break; | ||
|
||
case HitTypes.Transaction: | ||
|
||
request = new TransactionRequest(_proxy); | ||
break; | ||
|
||
|
||
default: | ||
throw new ApplicationException("Unknown hitType: " + hitType); | ||
} | ||
|
||
request.Parameters.Add(_protocolVersion); | ||
request.Parameters.Add(_trackingId); | ||
|
||
if (requestParameters != null) | ||
{ | ||
request.Parameters.AddRange(requestParameters); | ||
} | ||
|
||
return request; | ||
} | ||
} | ||
} |
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
src/GoogleMeasurementProtocol_NetStandard/Parameters/AppTracking/ApplicationId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.AppTracking | ||
{ | ||
/// <summary> | ||
/// Application identifier. | ||
/// </summary> | ||
public class ApplicationId : Parameter | ||
{ | ||
public ApplicationId(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "aid"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/GoogleMeasurementProtocol_NetStandard/Parameters/AppTracking/ApplicationInstallerId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.AppTracking | ||
{ | ||
/// <summary> | ||
/// Application installer identifier. | ||
/// </summary> | ||
public class ApplicationInstallerId : Parameter | ||
{ | ||
public ApplicationInstallerId(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "aiid"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/GoogleMeasurementProtocol_NetStandard/Parameters/AppTracking/ApplicationName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.AppTracking | ||
{ | ||
/// <summary> | ||
/// Specifies the application name. | ||
/// </summary> | ||
public class ApplicationName : Parameter | ||
{ | ||
public ApplicationName(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "an"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/GoogleMeasurementProtocol_NetStandard/Parameters/AppTracking/ApplicationVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.AppTracking | ||
{ | ||
/// <summary> | ||
/// Specifies the application version. | ||
/// </summary> | ||
public class ApplicationVersion : Parameter | ||
{ | ||
public ApplicationVersion(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "av"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/GoogleMeasurementProtocol_NetStandard/Parameters/ContentExperiments/ExperimentId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.ContentExperiments | ||
{ | ||
/// <summary> | ||
/// This parameter specifies that this user has been exposed to an experiment with the given ID. | ||
/// It should be sent in conjunction with the Experiment Variant parameter. | ||
/// </summary> | ||
public class ExperimentId : Parameter | ||
{ | ||
public ExperimentId(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "xid"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/GoogleMeasurementProtocol_NetStandard/Parameters/ContentExperiments/ExperimentVariant.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace GoogleMeasurementProtocol.Parameters.ContentExperiments | ||
{ | ||
/// <summary> | ||
/// This parameter specifies that this user has been exposed to a particular variation of an experiment. | ||
/// It should be sent in conjunction with the Experiment ID parameter. | ||
/// </summary> | ||
public class ExperimentVariant : Parameter | ||
{ | ||
public ExperimentVariant(string value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
public override string Name => "xvar"; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/GoogleMeasurementProtocol_NetStandard/Parameters/ContentInformation/ContentGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using GoogleMeasurementProtocol.Validators; | ||
|
||
namespace GoogleMeasurementProtocol.Parameters.ContentInformation | ||
{ | ||
public class ContentGroup : Parameter | ||
{ | ||
public byte GroupIndex { get; set; } | ||
|
||
public ContentGroup(string value, byte groupIndex = 1) : base(value) | ||
{ | ||
GroupIndex = groupIndex; | ||
Value = FormatValue(Value as string); | ||
} | ||
|
||
public override string Name | ||
{ | ||
get | ||
{ | ||
IndexValidator.ValidateContentGroupIndex(GroupIndex); | ||
|
||
return $"cg{GroupIndex}"; | ||
} | ||
} | ||
|
||
private string FormatValue(string value) | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
return value; | ||
} | ||
|
||
return value.Replace("\\\\", "\\").Trim('\\'); | ||
} | ||
} | ||
} |
Oops, something went wrong.