Appearance
Tracking with our .NET client
Relewise has a .NET SDK which, among other things, will make implementing tracking very easy.
It is available via NuGet.
Start by making a ITracker
-instance.
csharp
ITracker tracker = new Tracker(
new Guid("00000000-0000-0000-0000-000000000001"),
"your api key",
"server-url");
Read more about how to authenticate against our API here.
UserFactory
In order to provide the best user experience with personalization, it is important that users who give permission to be tracked (marketing cookies) are tracked with a unique ID. This unique ID can be advantageously accessed through your cookie consent supplier.
If the user has declined cookies, use the following factory method:
csharp
User.Anonymous();
If the user has accepted cookies:
csharp
User.ByTemporaryId("unique ID");
Best practices with TemporaryId
:
- Use an ID that is "long-living" and classified as 1st party, e.g. cookie or localStorage.
- Use same ID as the shop uses to recognize the user.
- Make sure the ID does not change, when the user completes an order.
If the user has logged in:
csharp
User.ByAuthenticatedId("PermanentId", "unique ID");
Best practices with AuthenticatedId
:
- If possible, use an ID that is semantic and constant.
- For a user journey that "starts" as a Temporary User, make sure to map the Temporary ID on the first request to Relewise. – this can also be done through a UserUpdate-request.
Example implementation for getting a User
-instance:
csharp
private User GetUser()
{
//"true" for demo-purposes, this should reflect the users cookie-consent choice.
bool userHasAcceptedCookies = true;
bool userIsLoggedIn = true;
User user;
if (userHasAcceptedCookies)
{
if (userIsLoggedIn)
{
user = User.ByAuthenticatedId("PermanentId", "unique ID");
}
else
{
user = User.ByTemporaryId("unique ID");
}
}
else
{
user = User.Anonymous();
}
return user;
}
If there is a logical segmentation of users, e.g. country, provide this segmentation via a custom key/value pair:
csharp
user.Classifications.Add("Country", "DK");
It is recommended to seek advice from Relewise before introducing segmentation by Classifications. Incorrect/excessive usage will potentially yield worse recommendations and search results.
Product Details Page (PDP)
On the Product Details Page (PDP), the following code must be called to track a product view:
csharp
await tracker.TrackAsync(new ProductView(
GetUser(),
new ProductAndVariantId("product id", "theVariantIdIfAny otherwise not provided")),
cancellationToken);
Product Listing Page / Collection Pages (PLP)
On the Product Listing Page (PLP), the following code is called to track a category page view:
csharp
await tracker.TrackAsync(new ProductCategoryView(
GetUser(),
"category id"),
cancellationToken);
Content Page
On the Content page, the following code is called to track a content page view:
csharp
await tracker.TrackAsync(new ContentView(
GetUser(),
"content id"),
cancellationToken);
For more advanced usages, you can provide a content-object to provide data about the content:
csharp
Content content = new("content-id");
// Optional: Provide additional information on the content.
// This can be used later during recommendations,
// if there is a need to e.g. filter and/or boost/bury content recommendations
content.Data["Type"] = "<page-type>";
await tracker.TrackAsync(new ContentView(GetUser(), content), cancellationToken);
Cart / Basket updates
In case of any change to the user's basket, the following is called with the full contents of the basket:
csharp
LineItem[] lineItems = new[]
{
new LineItem("product id 1", "variant id if any otherwise null", quantity: 1, lineTotal: 24.95m),
new LineItem("product id 2", "variant id if any otherwise null", quantity: 2, lineTotal: 125.50m)
};
await tracker.TrackAsync(
new Cart(GetUser(), subtotal: new Money("DKK", 125.95M), lineItems),
cancellationToken);
Orders
When user places an order, the following is called with the full contents of the order:
csharp
LineItem[] lineItems = new[]
{
new LineItem("product id 1", "variant id if any otherwise null", quantity: 1, lineTotal: 24.95m),
new LineItem("product id 2", "variant id if any otherwise null", quantity: 2, lineTotal: 125.50m)
};
await tracker.TrackAsync(new Order(
GetUser(),
new Money("DKK", 125.95M),
orderNumber: "the order number",
lineItems),
cancellationToken);