Skip to content

Commit

Permalink
Merge pull request #7 from mzanoni/master
Browse files Browse the repository at this point in the history
Added promo measurements
  • Loading branch information
mortenbock authored Apr 26, 2018
2 parents 7d1ca93 + 946b6d6 commit a018ec4
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/AnalyticsTracker.Tests/AnalyticsTracker.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<Compile Include="CommandTrackerTester.cs" />
<Compile Include="ConfigurationObjectTester.cs" />
<Compile Include="Messages\EnhancedEcommerce\AddToCartEventTester.cs" />
<Compile Include="Messages\EnhancedEcommerce\PromoClickMeasurementTester.cs" />
<Compile Include="Messages\EnhancedEcommerce\PromoViewMeasurementTester.cs" />
<Compile Include="Messages\EventTester.cs" />
<Compile Include="Messages\EnhancedEcommerce\ProductClickEventTester.cs" />
<Compile Include="Messages\TransactionMessageTester.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using Vertica.AnalyticsTracker.Commands.EnhancedEcommerce.FieldObjects;
using Vertica.AnalyticsTracker.Messages.EnhancedEcommerce;

namespace AnalyticsTracker.Tests.Messages.EnhancedEcommerce
{
[TestFixture]
public class PromoClickMeasurementTester
{
[Test]
public void RenderMessage_AddsPromoView()
{
var subj = new PromoClickMeasurement(new[] { new PromoFieldObject("JUNE_PROMO13", "June Sale") });
var renderedMessage = subj.RenderMessage();
Assert.That(renderedMessage, Is.StringContaining("{'event': 'promotionClick','ecommerce': {'promoClick': {'promotions': [{'id': 'JUNE_PROMO13','name': 'June Sale'}]}}}"));
}

[Test]
public void RenderMessage_AddsPromoViewWithOptional()
{
var subj = new PromoClickMeasurement(new[] { new PromoFieldObject("JUNE_PROMO13", "June Sale", creative: "banner1", position: "slot1") });
var renderedMessage = subj.RenderMessage();
Assert.That(renderedMessage, Is.StringContaining("{'event': 'promotionClick','ecommerce': {'promoClick': {'promotions': [{'id': 'JUNE_PROMO13','name': 'June Sale','creative': 'banner1','position': 'slot1'}]}}}"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using Vertica.AnalyticsTracker.Commands.EnhancedEcommerce.FieldObjects;
using Vertica.AnalyticsTracker.Messages.EnhancedEcommerce;

namespace AnalyticsTracker.Tests.Messages.EnhancedEcommerce
{
[TestFixture]
public class PromoViewMeasurementTester
{
[Test]
public void RenderMessage_AddsPromoView()
{
var subj = new PromoViewMeasurement(new[] { new PromoFieldObject("JUNE_PROMO13", "June Sale") });
var renderedMessage = subj.RenderMessage();
Assert.That(renderedMessage, Is.StringContaining("{'ecommerce': {'promoView': {'promotions': [{'id': 'JUNE_PROMO13','name': 'June Sale'}]}}}"));
}

[Test]
public void RenderMessage_AddsPromoViewWithOptional()
{
var subj = new PromoViewMeasurement(new[] { new PromoFieldObject("JUNE_PROMO13", "June Sale", creative: "banner1", position: "slot1") });
var renderedMessage = subj.RenderMessage();
Assert.That(renderedMessage, Is.StringContaining("{'ecommerce': {'promoView': {'promotions': [{'id': 'JUNE_PROMO13','name': 'June Sale','creative': 'banner1','position': 'slot1'}]}}}"));
}
}
}
3 changes: 3 additions & 0 deletions src/AnalyticsTracker/AnalyticsTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="Commands\EnhancedEcommerce\EnhancedEcommerceCommandBase.cs" />
<Compile Include="Commands\EnhancedEcommerce\FieldObjects\ImpressionFieldObject.cs" />
<Compile Include="Commands\EnhancedEcommerce\FieldObjects\ProductClickActionFieldObject.cs" />
<Compile Include="Commands\EnhancedEcommerce\FieldObjects\PromoFieldObject.cs" />
<Compile Include="Commands\EnhancedEcommerce\ProductClickCommand.cs" />
<Compile Include="Commands\EnhancedEcommerce\ProductDetailCommand.cs" />
<Compile Include="Commands\EnhancedEcommerce\FieldObjects\ProductFieldObject.cs" />
Expand All @@ -79,6 +80,8 @@
<Compile Include="Messages\EnhancedEcommerce\ProductClickEvent.cs" />
<Compile Include="Messages\EnhancedEcommerce\ProductDetailMeasurement.cs" />
<Compile Include="Messages\EnhancedEcommerce\ProductImpressionsMeasurement.cs" />
<Compile Include="Messages\EnhancedEcommerce\PromoClickMeasurement.cs" />
<Compile Include="Messages\EnhancedEcommerce\PromoViewMeasurement.cs" />
<Compile Include="Messages\EnhancedEcommerce\PurchaseMeasurement.cs" />
<Compile Include="Messages\EnhancedEcommerce\RemoveFromCartEvent.cs" />
<Compile Include="Messages\Event.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace Vertica.AnalyticsTracker.Commands.EnhancedEcommerce.FieldObjects
{
public class PromoFieldObject
{
private readonly Dictionary<string, object> _info = new Dictionary<string, object>();

public PromoFieldObject(string id, string name, string creative = null, string position = null)
{
_info["id"] = id;
_info["name"] = name;
_info["creative"] = creative;
_info["position"] = position;
}

public Dictionary<string, object> Info => _info;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using Vertica.AnalyticsTracker.Commands.EnhancedEcommerce.FieldObjects;

namespace Vertica.AnalyticsTracker.Messages.EnhancedEcommerce
{
public class PromoClickMeasurement : EnhancedEcommerceMeasurementBase
{
private readonly PromoFieldObject[] _promoFieldObjects;

public PromoClickMeasurement(PromoFieldObject[] promoFieldObjects) : base("promotionClick")
{
_promoFieldObjects = promoFieldObjects;
}

public override Dictionary<string, object> CreateMeasurement()
{
var promotions =
new Dictionary<string, object> { { "promotions", _promoFieldObjects.Select(i => i.Info).ToArray() } };

return new Dictionary<string, object>
{
{ "promoClick", promotions }
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using Vertica.AnalyticsTracker.Commands.EnhancedEcommerce.FieldObjects;

namespace Vertica.AnalyticsTracker.Messages.EnhancedEcommerce
{
public class PromoViewMeasurement : EnhancedEcommerceMeasurementBase
{
private readonly PromoFieldObject[] _promoFieldObjects;

public PromoViewMeasurement(PromoFieldObject[] promoFieldObjects)
{
_promoFieldObjects = promoFieldObjects;
}

public override Dictionary<string, object> CreateMeasurement()
{
var promotions =
new Dictionary<string, object> { { "promotions", _promoFieldObjects.Select(i => i.Info).ToArray() } };

return new Dictionary<string, object>
{
{ "promoView", promotions }
};
}
}
}

0 comments on commit a018ec4

Please sign in to comment.