Loading...
Area: Episerver Profile Store
Applies to versions: REST API v2

Track events

This topic describes the track event object in the Episerver Profile Store API. Tracked events are used for recording visitor interaction, for example viewing a website page, placing an order, or clicking a link in an email.

In this topic

How it works

The track event object contains the following property fields.

  • DeviceId [string]. The device the event was send from.
  • EventType [string]. The type of event.
  • Value [string]. A human-readable string for the event.
  • PageUri [string]. The URL where the event was made (if it was from a site).
  • RemoteAddress [string]. The IP address for the event visitor.
  • EventTime (datetime). The UTC time when the event occured.
  • CountryCode (string). The country from which the event was made.
  • Payload [object]. A property where any other custom values can be stored in the form of a JSON object.

Example

{
  "DeviceId"      : "91687965-bc76-49a2-862c-e014441b8f6b",
  "EventType"     : "home",
  "Value"         : "Visited the start page.",
  "PageUri"       : "https://example.com/en/",
  "RemoteAddress" : "::1",
  "Payload"       : {  
                      "name"          : "Home page",
                      "contentGuid"   : "440be34f-d08a-4a7e-b019-55448d065d28",
                      "contentLink"   : "163204",
                      "contentTypeID" : 170,
                      "parentLink"    : "163198"
                    },
  "EventTime"     : "2017-09-15T07:16:34.7957819Z",
  "CountryCode"   : "Localhost"
}

TrackEvents methods

An Authorization header must be added to the request. The value should be: 

epi-single {YOUR PROFILE STORE API KEY}

GET api/v2.0/TrackEvents

Gets events based on OData query. Profile Store follows Microsoft REST API Guidelines for supporting $filter, and $orderby.

The result window size is limited and must fit the top 10000 records, so the sum of $skip and $top values must be less than 10000. Defaut values of $skip is 0, $top is 100.

POST api/v2.0/TrackEvents

When a KQL query successfully runs, the response is the data belonging to track events.

The KQL query in this endpoint can return up to 1000 records.

Also, the KQL query should not be too complicated that it runs longer than 2 minutes and use more than 10% of cluster CPU.

Example request

POST /api/v2.0/TrackEvents/preview
Authorization: epi-single YourAPIKey
Content-Type: application/json-patch+json
accept: application/json
 
{ 
  "Query" : "Events
    | where EventTime between (todatetime('2019-01-01') .. endofday(now()))
        and EventType == 'pageview'
        and User.Email != ''
    | take 2", 
  "Scope" : "default" 
}

Example response data

{
  "items" : [
             {
               "TrackId"       : "",
               "DeviceId"      : "558356a7-86d2-4ca7-9c00-c01c46d81111",
               "EventType"     : "pageview",
               "Value"         : "Example page view",
               "Scope"         : "default",
               "PageUri"       : "http://example.com",
               "PageTitle"     : "Example Home",
               "RemoteAddress" : "192.168.0.1",
               "SessionId"     : "",
               "User"          : {
                                   "Email" : "hello@example.com",
                                   "Name"  : "John Smith"
                                 },
               "Payload"       : null,
               "CountryCode"   : "SE",
               "City"          : "",
               "EventTime"     : "2020-01-23T21:27:49.3361008Z"
             },
             {
               "TrackId"       : "",
               "DeviceId"      : "558356a7-86d2-4ca7-9c00-c01c46d82222",
               "EventType"     : "pageview",
               "Value"         : "Example page view from another device",
               "Scope"         : "default",
               "PageUri"       : "http://example.com",
               "PageTitle"     : "Example Home",
               "RemoteAddress" : "192.168.0.1",
               "SessionId"     : "",
               "User"          : {
                                   "Email" : "hello@example.com",
                                   "Name"  : "John Smith"
                                 },
               "Payload"       : null,
               "CountryCode"   : "SE",
               "City"          : "",
               "EventTime"     : "2020-01-23T21:27:59.8661238Z"
             }
            ],
  "count" : 2
}

DELETE api/v1.0/trackingevents/{scope}/{id}

The DELETE method deletes a tracking event for the given scope and tracking event Id.

Returns

  • HTTP 200 OK when a tracking event was deleted.
  • HTTP 404 NOT FOUND if tracking event does not exist.
  • HTTP 500 INTERNAL SERVER ERROR when an internal error occured in the deletion process. 

Note: If you experience a HTTP 500 error you can retry the operation again to get a succesful response.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Feb 06, 2020