Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
granstel committed Apr 20, 2021
1 parent 35ab484 commit 0bc131b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/Analytics/Analytics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Yandex.Dialogs.Models.Analytics
{
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class Analytics
{
public Analytics()
{
Events = new List<Event>();
}

public ICollection<Event> Events { get; set; }

public void AddEvent(string name, IDictionary<string, object> value)
{
var @event = new Event(name, value);

Events.Add(@event);
}
}
}
20 changes: 20 additions & 0 deletions src/Analytics/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Yandex.Dialogs.Models.Analytics
{
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class Event
{
public Event(string name, IDictionary<string, object> value)
{
Name = name;
Value = value;
}

public string Name { get; set; }

public IDictionary<string, object> Value { get; set; }
}
}
15 changes: 14 additions & 1 deletion src/OutputModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Yandex.Dialogs.Models.Interfaces;

Expand All @@ -9,6 +10,8 @@ public class OutputModel
{
public Response Response { get; set; }

public Analytics.Analytics Analytics { get; set; }

public AccountLinking StartAccountLinking { get; set; }

public Session Session { get; set; }
Expand Down Expand Up @@ -60,5 +63,15 @@ public void InitRequestGeolocation()
{
Response?.InitRequestGeolocation();
}

public void AddAnalyticsEvent(string name, IDictionary<string, object> value)
{
if (Analytics == null)
{
Analytics = new Analytics.Analytics();
}

Analytics.AddEvent(name, value);
}
}
}
4 changes: 2 additions & 2 deletions src/Yandex.Dialogs.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Language>C#</Language>
<Title>Yandex.Dialogs.Models</Title>
<Version>1.3.1</Version>
<PackageReleaseNotes>Add meta.interfaces.geolocation_sharing</PackageReleaseNotes>
<Version>1.4.0</Version>
<PackageReleaseNotes>Add analytics (https://yandex.ru/dev/dialogs/alice/doc/appmetrica.html)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 0bc131b

Please sign in to comment.