Tracking user actions (tracking) on the site

Features and installation methods

You can track user behaviour on your website, record their activity, actions with products, orders, etc. Based on the data obtained, segment the base by customer or user activity, which will allow you to conduct marketing campaigns much more effectively.

With connected tracking you have access to such functions as:

  • Segmentation by user activity on the site
  • Segmentation by customer activity
  • Tracking revenue from mailings
  • Tracking revenue, number of orders and average cheque for each user

There are two ways to set up tracking - script or API. You can choose the one that is easier to install for your team and fits your technical capabilities.

Installation instructions for each option are described below.

To calculate revenue using tracking, be sure to specify the site where tracking will be set up in “Account Settings” in enKod

Activity tracking (tracking) via API

All methods for tracking user actions are available в our API documentation in the "Tracking" section.

Please note that the methods will only work if the Tracking module is enabled for your account. If you want to use this functionality - contact your personal manager or at [email protected].

Features of API usage:

  • A session must be created for each new visitor
  • The “Start session” method must be called on each new visit (only for those visitors who have already been assigned a session).
  • All other methods should be called with session in the headers
  • It is not recommended to transfer the purchase without a communication channel (email, phone)

When setting up tracking via API, we cannot automatically detect if a contact is in the database (similar to the script and eksubsemail parameter). But you can configure the same logic yourself:

  1. Use the eksubsemail parameter in URL emails, in the value of which pass the recipient's email using a personalisation tag {{user_guide:tracking:subscriber_email}}
  2. When opening the site, always call API-метод /v1/sessions/
  3. After the contact has navigated to the site, call метод /v1/subscribe/, in which pass:
    • X-Session-Id of the contact from step 2
    • source= 'url_param'
    • email (fields) from {{user_guide:tracking:subscriber_email}}

Tracking actions (tracking) using a script

Put the script on the site before the closing tag </body>.

<script type="text/javascript">
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '//cdn.enkod.ru/script/enpop.min.js';
    script.async = true;
    var first = document.getElementsByTagName('script')[0];
    first.parentNode.insertBefore(script, first);
    var enKodBox = window.enKodBox = window.enKodBox || {};    
    var ekEvents = window.ekEvents || [];
    enKodBox['token'] = 'system_name_of_the_account';
</script>

The system name of the account is set when you create an account in the platform and is not equal to the sending domain or website address. You can get the system name from your account manager.

An appeal to the script will look like this:

<script type="text/javascript">
    ekEvents.push('action_name', { param1: 'and', param2: 'object', param3: 'with parameters' })
</script>

The first argument is the name of the action, and the second argument is a hashmap with parameters.

The list of events that can be tracked is described below.

Opening a page with a product

<script type="text/javascript">
    ekEvents.push('productOpen', { productId: 'артикул товара', groupId: 'идентификатор группы товаров', param: 'value' }); 
</script>

Reserved field names

Name Type Description Mandatory
productId String Product ID Mandatory

After the mandatory parameter you can specify any product parameters that you want to pass to the service. For example, product category, group, etc.

Adding a product to the basket

Reserved field names

Name Type Description Mandatory
productId String ProductId Mandatory
count Int Item count. Default value is 1. You can assign any value to Optional

This method can be used in several ways. Let's look at them with examples:

  • adding a single item to the basket
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'артикул товара'}); 
</script>
  • adding an item to the basket with additional fields
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'артикул товара', category: '1', group: 'some-group', param: 'value'}); 
</script>
  • adding several identical items with one method call. For this purpose it is enough to pass the count parameter.
 
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'артикул товара', count: 2}); 
</script>
  • adding several different products by one method call. An array with goods is written into the parameter, if count is not specified, the default value is 1.
<script type="text/javascript">
    ekEvents.push('productAdd', [{ productId: 'артикул товара', count: 2}, { productId: 'другой артикул', count: 5}]); 
</script>

Deleting an item from the basket

Reserved field names

Name Type Description Mandatory
productId String ProductID Required
count Int Quantity of product. Default value is 1. Can be set to any value Optional

This method can be used in several ways. Let's look at them with examples:

  • removing one item from the basket
<script type="text/javascript">
    ekEvents.push('productRemove', { productId: 'артикул товара'}); 
</script>
  • deleting several identical items by one method call. For this purpose it is enough to pass the count parameter.
<script type="text/javascript">
    ekEvents.push('productRemove', { productId: 'артикул товара', count: 2}); 
</script>
  • deletion of several different products by one method call. The parameter contains an array with goods, if count is not specified, the default value is 1.
<script type="text/javascript">
    ekEvents.push('productRemove', [{ productId: 'артикул товара', count: 2}, { productId: 'другой артикул', count: 5}]); 
</script>

Adding a product to favourites

Reserved field names

Name Type Description Mandatory
productId String ProductId Mandatory

This method can be used in several ways. Let's look at them with examples:

  • adding one product to favourites
<script type="text/javascript">
    ekEvents.push('productLike', { productId: 'артикул товара'}); 
</script>
  • adding a product to favourites with additional fields
<script type="text/javascript">
    ekEvents.push('productLike', { productId: 'артикул товара', category: '1', group: 'some-group', param: 'value'}); 
</script>
  • adding several different products with one method call. The array with goods is written into the parameter.
<script type="text/javascript">
    ekEvents.push('productLike', [{ productId: 'артикул товара'}, { productId: 'другой артикул'}]); 
</script>

Deleting an item from the list of favourites

Reserved field names

Name Type Description Mandatory
productId String ProductId Mandatory

This method can be used in several ways. Let's look at them with examples:

  • removing one product from the list of favourites
<script type="text/javascript">
    ekEvents.push('productDislike', { productId: 'артикул товара'}); 
</script>
  • deleting several different products by one method call. The array with goods is written into the parameter.
<script type="text/javascript">
    ekEvents.push('productDislike', [{ productId: 'артикул товара'}, { productId: 'другой артикул'}]); 
</script>

Purchase

Reserved field names

Name Type Description Mandatory
orderId String ID of the purchase. If not passed, it is generated automatically Mandatory
items [{}] Array with items Mandatory
sum Float/Int Purchase amount Mandatory for outputting revenue in the interface
productId String Product item Mandatory for recommendation module
price Float/Int Price of product Mandatory for recommendation module
count Int Quantity of each product in the order Mandatory for the recommendations module
<script type="text/javascript">
    ekEvents.push('productBuy',{orderId: 'id',  sum: 1000,  items: [{productId: 'Артикул товара 1', count: 5, price: 10}, {productId: 'Артикул товара 2', count: 1, price: 50}]})
</script>
  • transfer of additional order parameters
<script type="text/javascript">
    ekEvents.push('productBuy',{orderId: 'id', items: [{productId: 'Артикул товара', count: 5}], finalPrice: '100', param: 'value'})
</script>

If you want to collect contact information at checkout and record the order itself in enKod, then use a sequential call to the subscribe and checkout methods:

<script type="text/javascript">
    async function subAndOrder() {
            await ekEvents.push('subscribe', {
                source: 'form',
                integrations: [1],
                groups: [1, "sysname"],
                fields: {
                    email: '[email protected]',
                    lastName: '',
                    phone: '70000000000'
                }
            })
            await ekEvents.push('productBuy', {
                orderId: '84781',
                items: [{
                    productId: '5y347p92',
                    size: '92',
                    count: 1,
                    price: 230
                }],
                sum: 230
            })
        }
        subAndOrder()
</script>

Capture the contact on any of the forms (login, registration, quick purchase)

Reserved field names

Name Type Description Mandatory
groups Int/String [] Array of mailing group ids and/or system names of mailing groups to be assigned to the subscriber when added to the platform Optional
fields Object List of basic fields Optional
extraFields ObjectList of extra fields Optional
mainChannel StringThe main channel is either 'email' or 'phone'. It is passed only if 2 channels are passed at once in subscribe method Optional

Field parameters: subscriber information

Name Type Description Mandatory
email String User email Mandatory
firstName String Subscriber name Optional
lastName String Subscriber's last name Optional
phone String Subscriber's phone number Optional
<script type="text/javascript">
    ekEvents.push('subscribe',{source: 'form', groups: [18, "group_name"], fields: {email: '[email protected]', firstName: 'Имя', lastName: 'Фамилия', phone: '7900000000'}, extraFields: {systemName: 'value', systemName2: 'value'}})
</script>

In order for tracking to determine the email address of a contact who has reached the site from an email message, for all links in the message you must specify the URL parameter eksubsemail, in the value of which you must pass the recipient's email using the personalisation tag {{user_guide:tracking:subscriber_email}}.

Capture additional information about a contact without linking to email address

Used to transfer data about a subscriber without binding to his/her email address. For example: recording the subscriber's city, phone number, age, etc. before the subscriber registers or logs in.

Reserved field names

Name Type Description Mandatory
extraFields ObjectList of extra fields Mandatory
ekEvents.push('addExtraFields',{extraFields: {city: 'Рязань', systemName: 'value'}})

Opening any page of the site

Method used to segment contacts based on their browsing history on the site. Should be installed on every page of the site. Together with the ekEvents.push('subscribe') method, it allows you to track visits to a page by specific users and segment them based on this data.

ekEvents.push('pageOpen')

Calling a custom event

ekEvents.push('event', {email:'[email protected]', phone:'79000000000', params: {param1: 'value1'}});

Where:

  • event is the system name of the event created in the enKod ➔ Custom events
  • param - system name of parameter
  • value - value of the parameter

A contact's email and/or phone number can be passed with the method (not necessarily). If email and/or phone number are not passed or contacts with such identifiers are not found in your account, we will bind the event to a session if we know it. If the event is linked to a session and there is no session (and there is no email or phone number transmitted in your account), the event will not be displayed in enKod.

Setting up tracking on a website with Google Tag Manager

To use our script and methods in case you are using Google Tag Manager, you need to follow these steps:

1. To install the script you need to create a separate tag in GTM.

You can read more about tags in GTM at </ignore>мануале Google

To place a script inside a tag in GTM, you need to create a tag with “Custom HTML” type and “Once per event” tag triggering option (by default). Place the script code in the tag body, specifying the system name corresponding to your account (not equal to the site domain or account name, you can check with your account manager).

The appropriate trigger to start the tag should be based on the first load of any of the site pages or page view (the trigger is selected according to the conditions you need).

Read more about triggers in </ignore>мануале Google

2. To use tracking methods, you need to create a tag with the “Custom HTML” type for each method. In the body of the tag for the parameter values you need to specify the variables you use on your site.

For example, let's consider a method template for adding an item to cart and a working method in GTM with filled in client variables.

<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'артикул товара', variant: 'тип товара', category: 'категория товара', count: 'кол-во товаров'}); 
</script>

For each tag, you must set the trigger at which this method should be triggered and the exceptions (if necessary).

3. After tags are created, they should be saved and published.

Checking the correctness of tracking methods in DevTools

Open the site, go to developer tools (F12 or Fn+F12).

Open the required DevTools section according to the screenshot.

Open any product, perform any target action for which tracking methods have been set (opening a card, adding to cart, ordering, adding to favourites, etc.).

Check that all enKod methods work correctly and without errors - return the status “200 OK”.

Last modified: 2023.12.13 10:29 by Anastasia Aniskova