User activity tracking (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 install tracking - script or API. You can choose the one that is easier for your team to install 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) by API

All methods for tracking user actions are available in 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 using the API:

  • 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 by API, we cannot automatically detect if a contact is in the database (similar to the script and eksubsemail parameter). But you can set up the same logic yourself:

  1. Use the eksubsemail URL-parameter in your emails, and in its value pass the recipient's email using a personalisation tag {{subscriber_email}}
  2. When opening a site, always call API-method /v1/sessions/
  3. After the contact goes to the site, call method /v1/subscribe/, in which pass:
    • X-Session-Id of the contact from step 2
    • source= 'url_param'
    • email (fields) from {{subscriber_email}}

Please note that when setting up tracking by API, the segment conditions for pop-ups based on basket and page visits will not work. To use these conditions, you need to pass basket change events using the JS script method.

Activity tracking (tracking) using a JS script

The script will be loaded only once when the website is loaded for the first time, it does not affect the speed of switching between pages. All methods are called in the browser cache in the background and are invisible to the user.

Place 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 creating 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.

Calling 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 product page

<script type="text/javascript">
    ekEvents.push('productOpen', { productId: 'product vendor code', groupId: 'product group identifier', param: 'value' }); 
</script>

Reserved field names

Name Type Description Mandatory
productId String Product ID Mandatory

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

Opening a page with a product category

<script type="text/javascript">
    ekEvents.push('categoryOpen', { categoryId: 'category identifier', categoryUrl: 'URL of the category page' }); 
</script>

Reserved field names

Name Type Description Mandatory
categoryId Int Product category identifier Mandatory
categoryUrl String Link to the category page on the website Optional

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 product to the basket
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'product vendor code'}); 
</script>
  • adding a product to the basket with additional fields
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'product vendor code', category: '1', group: 'some-group', param: 'value'}); 
</script>
  • adding several identical products by one method call. To do this, just pass the parameter count.
 
<script type="text/javascript">
    ekEvents.push('productAdd', { productId: 'product vendor code', count: 2}); 
</script>
  • adding several different products by one method call. An array of products is written into the parameter, if count is not specified, the default value is 1.
<script type="text/javascript">
    ekEvents.push('productAdd', [{ productId: 'product vendor code', count: 2}, { productId: 'another vendor code', count: 5}]); 
</script>

Removing a product 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 product from the basket
<script type="text/javascript">
    ekEvents.push('productRemove', { productId: 'product vendor code'}); 
</script>
  • removing several identical products by one method call. To do this, just pass the parameter count.
<script type="text/javascript">
    ekEvents.push('productRemove', { productId: 'product vendor code', count: 2}); 
</script>
  • removing several different products by one method call. An array of products is written into the parameter, if count is not specified, then the default value is 1.
<script type="text/javascript">
    ekEvents.push('productRemove', [{ productId: 'product vendor code', count: 2}, { productId: 'another vendor code', count: 5}]); 
</script>

Adding a product to favorites

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 favorites
<script type="text/javascript">
    ekEvents.push('productLike', { productId: 'product vendor code'}); 
</script>
  • adding a product to favorites with additional fields
<script type="text/javascript">
    ekEvents.push('productLike', { productId: 'product vendor code', category: '1', group: 'some-group', param: 'value'}); 
</script>
  • adding several different products by one method call. An array of products is written into the parameter.
<script type="text/javascript">
    ekEvents.push('productLike', [{ productId: 'product vendor code'}, { productId: 'another vendor code'}]); 
</script>

Removing a product from favorites

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 favorites
<script type="text/javascript">
    ekEvents.push('productDislike', { productId: 'product vendor code'}); 
</script>
  • removing several different products by one method call. An array of products is written into the parameter.
<script type="text/javascript">
    ekEvents.push('productDislike', [{ productId: 'product vendor code'}, { productId: 'another vendor code'}]); 
</script>

Adding a product to comparison

Reserved field names

Name Type Description Mandatory
productId String ProductId Mandatory
<script type="text/javascript">
    ekEvents.push('productComparison', {product: {productId: 'product vendor code'}}); 
</script>

Removing a product from comparison

Reserved field names

Name Type Description Mandatory
productId String ProductId Mandatory
<script type="text/javascript">
    ekEvents.push('productComparisonRemove', {product: {productId: 'product vendor code'}}); 
</script>

Clearing the comparison

<script type="text/javascript">
    ekEvents.push('productComparisonClean'); 
</script>

Order

Reserved field names

Name Type Description Mandatory
orderId String Order ID. If not passed, it is generated automatically Mandatory
items [{}] Array of products Mandatory
sum Float/Int Order amount Mandatory for outputting revenue in the interface
productId String Product ID Mandatory for recommendation module
price Float/Int Product price 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: 'product vendor code 1', count: 5, price: 10}, {productId: 'product vendor code 2', count: 1, price: 50}]})
</script>
  • passing additional order parameters
<script type="text/javascript">
    ekEvents.push('productBuy',{orderId: 'id', items: [{productId: 'product vendor code', 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', {
                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>

Order return

Reserved field names

Name Type Description Mandatory
orderId String ID of the order that needs to be returned Mandatory
<script type="text/javascript">
     ekEvents.push('orderReturn',{orderId: 'id'})
</script>

When processing a return, the revenue parameters will be recalculated, the number of orders and purchased products will not change.

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

You do not need to connect the tracking module to use this method

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
cartMergeMethod String• merge - The contents of the existing contact's basket will be merged with the contents of the basket of the contact sent in the request;
• ignore - The contents of the basket of the contact sent in the request will be ignored, the contents of the existing contact's basket will be saved
Optional
favouriteMergeMethod String• merge - The content of the existing contact's favorites will be merged with the content of the favorites of the contact sent in the request;
• ignore - The content of the favorites of the contact sent in the request will be ignored the contents of the existing contact's favorites will be saved
Optional

Contacts are added and updated according to the addAndUpdate method:

  • new contacts will be added, existing contacts will be updated.

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',{groups: [18, "group_name"], fields: {email: '[email protected]', firstName: 'name', lastName: 'surname', 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 {{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: 'London', 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 Google Help

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 Google Help

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: 'product vendor code', variant: 'product type', category: 'product category', count: 'product quantity'}); 
</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: 2024.11.07 06:34 by Anastasia Aniskova