Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d11a79e
LAPP-51 Creating basic sample project
cgalan-applaudo Apr 22, 2020
8925554
LAPP-52 Creating example sample project
cgalan-applaudo Apr 22, 2020
ea861cd
LAPP-53 Adding docker support
cgalan-applaudo Apr 22, 2020
30885d9
LAPP-54 Adding MakeFile
cgalan-applaudo Apr 22, 2020
6f4d2d2
Merge branch 'master' into feature/LAPP-51
lubird Apr 29, 2020
29a2e5c
Merge branch 'master' into feature/LAPP-51
lubird May 8, 2020
a1418ac
Merge branch 'master' into feature/LAPP-51
cgalan-applaudo May 13, 2020
8ebda5e
Merge branch 'master' into feature/LAPP-51
cgalan-applaudo May 15, 2020
79d990d
Merge branch 'feature/LAPP-51' into feature/LAPP-52
cgalan-applaudo May 15, 2020
b279fe1
Merge branch 'feature/LAPP-51' into feature/LAPP-53
cgalan-applaudo May 15, 2020
9d7ed7c
Merge branch 'feature/LAPP-51' into feature/LAPP-54
cgalan-applaudo May 15, 2020
c21bc4c
Merge branch 'master' into feature/LAPP-51
lubird Jun 22, 2020
06cf528
Merge branch 'master' into feature/LAPP-52
lubird Jun 22, 2020
8bea33c
Merge pull request #122 from cgalan-applaudostudios/feature/LAPP-51
lubird Jul 6, 2020
9f33e6d
Merge branch 'sample_apps' into feature/LAPP-52
lubird Jul 6, 2020
0bb991e
Merge pull request #123 from cgalan-applaudostudios/feature/LAPP-52
lubird Jul 6, 2020
bbc1cd7
Merge branch 'master' into feature/LAPP-53
lubird Jul 6, 2020
dd73495
Merge branch 'sample_apps' into feature/LAPP-53
lubird Jul 6, 2020
87a9f05
Merge pull request #124 from cgalan-applaudostudios/feature/LAPP-53
lubird Jul 6, 2020
23ebc19
Merge branch 'sample_apps' into feature/LAPP-54
lubird Jul 6, 2020
74e08f3
Merge pull request #125 from cgalan-applaudostudios/feature/LAPP-54
lubird Jul 6, 2020
2b8e8af
Fixed incorrect case for Dockerfile
lubird Jul 8, 2020
c015935
Bumped version of Analytics.NET library to 3.4.1
lubird Jul 9, 2020
c3b012d
Added README with Sample app instructions
lubird Jul 9, 2020
746b87f
Merge branch 'master' into sample_apps
lubird Jul 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
464 changes: 261 additions & 203 deletions Analytics.NET.sln

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions Samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Reference Apps
================

These reference apps are provided as an example of using the Analytics.NET library. The folder is structure in the following way:

### `Sloth.Basic`
A sample app which imports the Segment SDK and exhibits the full functionality exposed without major configuration changes.

### `Sloth.Enterprise`
A sample app which imports the Segment SDK and exhibits how to configure Segment SDK to operate at high throughput, operate under proxy service, leverage batching and data compression.

This app demonstrates common configuration changes such as custom queue size, API hostname, and compression.

### `Sloth.Common`
A library of common functionality shared by both reference apps. This is not meant to function as a standalone app.

Usage
=====

Create a new Source (or use an existing one) from within the [Segment App](https://app.segment.com/). Take note of your [write key](https://segment.com/docs/connections/find-writekey/).

First, set an environment variable `writeKey` to your source's write key:

```
export writeKey=YOURWRITEKEY
```

Within either `Sloth.Basic` or `Sloth.Enterprise`, the easiest way to run the apps is to use Docker:

```
make docker_run
```

Alternatively, you can run the apps directly on your machine, using [.NET Core 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1):

```
make run
```

**Note:** out of the box, `Sloth.Enterprise` is configured to send data to `https://api.segment.dev`, which doesn't exist. This is purely done as a demonstration of the host configuration functionality. If you want to see the library working, you can point it to a working hostname or remove that configuration parameter.
21 changes: 21 additions & 0 deletions Samples/Sloth.Basic/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/runtime:2.1-stretch-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["Samples/Sloth.Basic/Sloth.Basic.csproj", "Samples/Sloth.Basic/"]
COPY ["Samples/Sloth.Common/Sloth.Common.csproj", "Samples/Sloth.Common/"]
RUN dotnet restore "Samples/Sloth.Basic/Sloth.Basic.csproj"
COPY . .
WORKDIR "/src/Samples/Sloth.Basic"
RUN dotnet build "Sloth.Basic.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Sloth.Basic.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Sloth.Basic.dll"]
10 changes: 10 additions & 0 deletions Samples/Sloth.Basic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: run docker_build docker_run

run:
dotnet run Sloth.Basic.csproj

docker_build:
docker build -t 10krps -f Dockerfile ../..

docker_run: docker_build
docker run -e writeKey -e events 10krps
41 changes: 41 additions & 0 deletions Samples/Sloth.Basic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Segment;
using Sloth.Common;
using Environment = System.Environment;

namespace Sloth.Basic
{
class Program
{
private const int UserJourneys = 500;

static void Main(string[] args)
{
var writeKey = Environment.GetEnvironmentVariable("writeKey");

if (string.IsNullOrWhiteSpace(writeKey)) throw new ArgumentException(nameof(writeKey));

OnExecute(writeKey);
}

private static void OnExecute(string writeKey)
{
Analytics.Initialize(writeKey);

Logger.Handlers += Utils.LoggerOnHandlers;

for (var i = 0; i < UserJourneys; i++)
{
Utils.DoJourney();
}

// sending all pendant messages
Analytics.Client.Flush();

Utils.PrintSummary();

Analytics.Client.Dispose();
}

}
}
13 changes: 13 additions & 0 deletions Samples/Sloth.Basic/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"Sloth.Basic": {
"commandName": "Project"
},
"Docker": {
"commandName": "Docker",
"environmentVariables": {
"writeKey": ""
}
}
}
}
23 changes: 23 additions & 0 deletions Samples/Sloth.Basic/Sloth.Basic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Analytics" Version="3.4.1-alpha" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Sloth.Common\Sloth.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions Samples/Sloth.Common/Sloth.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Analytics" Version="3.4.1-alpha" />
</ItemGroup>

</Project>
192 changes: 192 additions & 0 deletions Samples/Sloth.Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Segment;

namespace Sloth.Common
{
public class Utils
{
public static void DoJourney()
{
var anonUserId = Guid.NewGuid().ToString();
var user1Id = Guid.NewGuid().ToString();
var user2Id = Guid.NewGuid().ToString();
var accountId = Guid.NewGuid().ToString();

AnonymousUserVisitsWebsite(anonUserId);
UserU1SignsUpForNewTrialAccount(anonUserId, user1Id, accountId);
UserU1SendInviteToAnotherUserU2(user1Id);
UserU1SignsOutOfApp(user1Id);
UserU1SignsBackIntoApp(user1Id);
TrialsEndsAndUserU1RequestsAccountToBeDeleted(user1Id, user2Id, accountId);
}

public static Logger.LogHandler LoggerOnHandlers = (level, message, args) =>
{
if (args != null)
message = args.Keys.Aggregate(message,
(current, key) => current + $" {"" + key}: {"" + args[key]},");

Console.WriteLine($"[{level}] {message}");
};

private static void AnonymousUserVisitsWebsite(string anonUserId)
{
//identify page load
Analytics.Client.Page(anonUserId, "Home");

//identify anon user
Analytics.Client.Identify(anonUserId, new Dictionary<string, object>
{
{"subscription", "inactive"},
});

// track CTA click
Analytics.Client.Track(anonUserId, "CTA Clicked", new Dictionary<string, object>
{
{"plan", "premium"},
});
}
private static void UserU1SignsUpForNewTrialAccount(string anonUserId, string user1Id, string accountId)
{
//page
Analytics.Client.Page(anonUserId, "Sign Up", new Dictionary<string, object>
{
{"url", "https://wwww.example.com/sign-up"},
});

//new account created
Analytics.Client.Track(anonUserId, "Account Created", new Dictionary<string, object>
{
{"account_name", "Acme Inc"},
});

//create new user
Analytics.Client.Track(user1Id, "Signed Up", new Dictionary<string, object>
{
{"type", "organic"},
{"first_name", "Peter"},
{"last_name", "Gibbons"},
{"email", "pgibbons@initech.com"},
{"phone", "410-555-9412"},
{"username", "pgibbons"},
{"title", "Mr"},
});

// alias anon id to new user
Analytics.Client.Alias(anonUserId, user1Id);

//add user to account (group)
Analytics.Client.Group(user1Id, accountId, new Dictionary<string, object>
{
{"role", "Owner"},
});

//confirm track call
Analytics.Client.Track(user1Id, "Account Added User", new Dictionary<string, object>
{
{"role", "Owner"},
});

//start account trial
Analytics.Client.Track(user1Id, "Trial Started", new Dictionary<string, object>
{
{"trial_start_date", DateTime.Now},
{"trial_end_date", DateTime.Now.AddDays(7)},
{"trial_plan_name", "premium"},
});
}

private static void UserU1SendInviteToAnotherUserU2(string user1Id)
{
//page
Analytics.Client.Page(user1Id, "Dashboard", new Dictionary<string, object>
{
{"url", "https://wwww.example.com/dashboard"},
});

//invite sent
Analytics.Client.Track(user1Id, "Invite Sent", new Dictionary<string, object>
{
{"invitee_email", "janedoe@gmail.com"},
{"invitee_first_name", "Jane"},
{"invitee_last_name", "Doe"},
{"invitee_role", "Admin"},
});
}

private static void UserU1SignsOutOfApp(string user1Id)
{
//signed out
Analytics.Client.Track(user1Id, "Signed Out", new Dictionary<string, object>
{
{"username", "pgibbons"},
});
}

private static void UserU1SignsBackIntoApp(string user1Id)
{
//page
Analytics.Client.Page(user1Id, "Dashboard", new Dictionary<string, object>
{
{"url", "https://www.example.com/dashboard"},
});

// signed in
Analytics.Client.Track(user1Id, "Signed In", new Dictionary<string, object>
{
{"username", "pgibbons"},
});
}

private static void TrialsEndsAndUserU1RequestsAccountToBeDeleted(string user1Id, string user2Id, string accountId)
{
//page
Analytics.Client.Page(user1Id, "Dashboard", new Dictionary<string, object>
{
{"url", "https://wwww.example.com/account/settings"},
});

//trial ended
Analytics.Client.Track(accountId, "Trial Ended", new Dictionary<string, object>
{
{"trial_start_date", DateTime.Now},
{"trial_end_date", DateTime.Now.AddDays(7)},
{"trial_plan_name", "premium"},
});

//track user requests account deletion on upgrade request
Analytics.Client.Track(user1Id, "Account Delete Requested", new Dictionary<string, object>
{
{"account_id", accountId},
});

//remover User (U2) from account
Analytics.Client.Track(user2Id, "Account Removed User");

//remover User (U1) from account
Analytics.Client.Track(user1Id, "Account Removed User");

//delete Account
Analytics.Client.Track(accountId, "Account Deleted", new Dictionary<string, object>
{
{"account_name", "Acme Inc"},
});

//sign out User (U1)
Analytics.Client.Track(user1Id, "Signed Out", new Dictionary<string, object>
{
{"username", "pgibbons"},
});
}

public static void PrintSummary()
{
Console.WriteLine($"Submitted: {Analytics.Client.Statistics.Submitted}");
Console.WriteLine($"Failed: {Analytics.Client.Statistics.Failed}");
Console.WriteLine($"Succeeded: {Analytics.Client.Statistics.Succeeded}");

}
}
}
Loading