Javascript SDK

Renta Javascript SDK — allows you to collect events, sessions and user-level data from the website. SDK provides data streaming to the following destinations: 

  • Google BigQuery
  • Clickhouse
  • Facebook Conversions API
  • Webhooks

The advantage of this data source is the ability to support server-side integration, which provides data collection on behalf of the first-party data

The whole process of setting up data collection can be divided into several simple steps:

  1. Project creation;
  2. Custom domain creation;
    Required only for server-side implementation; 
  3. Event tracker injection.  

Project creation

Select Javascript in the integration Catalog to create a new data source.

 

Then specify the following settings:

Site URL

Specify the URL of the site for which you want to set up tracking.

Server-side implementation

Allows you to configure server-side tracking. By default, tracking is done by Renta, but we strongly recommend to use a subdomain of your website.

In order o do this, enable server-side implementation and specify the following settings:

Custom domain

Enter the subdomain of your website on behalf of which the tracking will take place in the Custom domain field. For instance, collect.yourdomain.com

IP address

CopyIP address of the dedicated server for your project and specify it as the A-record for the specified subdomain. If you do not perform the configuration by yourself, then use the instructions for the IT department.

Installing Code

Copy the received code into the Installing Code field install it on all pages of the site. For instance, using Google Tag Manager.

Now you can go to the event settings on the site side.

Configuring Event Tracking

Using the Javascript SDK, you can configure 4 types of events:

Event typeDescription
pageCaptures information about page views.
trackProvides tasks for tracking user actions. For instance to track transactions or subscribe to a newsletter.
identity Recommended to use only to collect users’ personal data. Helps to build a user profile.
groupThe event is used to track a group of users.

Page

This is the basic event that sends information about the page view. Recommended to call this event on all pages of the site.

To call a page view event, use the code below:

<script> 
 analytics.page()
</script> 

You can also specify additional attributes if the standard data is not enough. To modify a page type event properly, read this guide.

Track

Use it to record any user actions on the site. You can create custom event names with any number of descriptive attributes.

You can see the scenarios for using this type of event below:

  • Registration in the product;
  • Subscribe to the newsletter;
  • Making a transaction in the online store;

Thus, you can create any events that are valuable for your project.

Example of calling javascript code to commit a transaction:

<script>
  analytics.track('Transaction completed', {
  transactionId: "ABC00001",
  transactionRevenue: 1000
});
</script>

Each track event consists of:

Field nameMandatoryField description
Event nameThe name of the event. For instance, Transaction completed.
Properties

This is any additional information that you can send along with the event.

You can specify any number of additional attributes.

As an example, the transactionId and transactionRevenue variables are transfered to the Transaction completed event. They describe the amount and number of order. These variables are additional attributes of the event. You can delete them, rename them, or specify your own attributes. 

Identity

It is necessary to use Identity only at the moment of user identification. Below are the scenarios when one should call this event type:

  • After successful registration;
  • After successful authorization;
  • When the user updated their contact information;

To call the event, use javascript code:

<script>
 analytics.identify("userid_variable", {
  name: "Elon Musk",
  email: "elon@tesla.com",
  company: "Tesla Motors"
 });
</script>

In addition to the standard fields, identity supports the following fields:

Fields nameMandatoryField description
userIdUnique user ID in your database.
Properties

This is any additional information that you can send along with the event.

 

You can specify any number of additional attributes.

 

As an example, the javascript code contains the variables name, email, company. These variables are additional attributes of the event. You can delete them, rename them, or specify your own attributes. 

Group

The event is used to unite users into a common group.

The name of the company, department, or project can be used as a group. Thus, you can use any internal identifier in your system.

To call the event, use javascript code:

<script>
 analytics.group("groupid_variable", {
  company: "Tesla",
  industry: "Auto Manufacturing",
  employees: 70757
 });
</script>

In addition to the standard fields, group supports the following fields:

Field nameMandatoryField description
groupIdUnique ID of the group in your database.
Properties

This is any additional information that you can send along with the event.

 

You can specify any number of additional attributes.

 

As an example, the javascript code contains variables company, industry, employees. These variables are additional attributes of the event. You can delete them, rename them, or specify your own attributes. 

Structure of standard fields

Initially, events of all types come with a standard list of fields that are available for transmission in server-side integrations and are also stored in a separate table during DWH integration.

The list of standard fields, as well as their description, is available in the table below:

Field nameType of dataDescription
dateTimedatetimeDate and time of the event in UTC
datedateDate of the event in UTC
sendAtdatetimeDate and time when the event was sent from the client side
eventIdStringUnique Event ID
eventTypeStringEvent type
eventNameStringEvent name
propertiesStringJson object that contains custom event attributes
anonymousIdStringUnique cookie values
userIdStringUserId number. Contains the value passed to Google Analytics.
groupIdStringUnique group value (only available for a group type event)
contentStringMaintance of utm_content
mediumStringMaintance ofutm_medium
sourceStringMaintance of utm_source
termStringMaintance of utm_term
campaignStringMaintance of utm_campaign
dataSourceStringThe data source for the request. Initialy, requests from analytics.js they will have the web value, and requests from the mobile SDK will have the app value.
deviceStringDevice type: desktop, tablet, mobile, TV. 
deviceBrowserStringBrowser (for instance, Chrome or Firefox).
deviceBrowserVersionStringBrowser version.
deviceOperatingSystemStringOperating system(for instance, Macintosh or Windows).
deviceOperatingSystemVersionStringOperating system version.
deviceIpStringIP-adress
countryStringCountry
cityStringCity
regionStringRegion
deviceUserAgentStringUser Agent
deviceScreenHeightIntResolution of the user’s screen in pixels by height
deviceScreenWidthIntResolution of the user’s screen in pixels by width
deviceViewPortHeightIntThe size of the viewing area in the browser by height
deviceViewPortWidthIntThe size of the viewing area in the browser by width
deviceDocEncodingStringEncoding. For instance, UTF-8.
locationStringURL with additional parameters. For instance: https://site.com/catalog/platya?page=2
hostnameString

Domain. 

For instance: https://site.com/

pathString

Path of the pages URL. 

For instance: /catalog/platya

titleStringTitle of the page.
pageString

The full URL path.

For instance: https://site.com/catalog/platya

documentReferrerStringIf the medium field has the referral value, the path of the traffic source is indicated here, and the host name is contained in the source field.
fbclidStringThe Facebook Ads click ID that is passed to the URL when the ad is clicked.
gclidStringThe Google Ads click ID that is passed to the URL when the ad is clicked.
ydclidStringThe Yandex Direct click ID that is passed to the URL when the ad is clicked.
ga_cookie_idStringThe unique meaning of Google Analytics cookies
ym_cookie_idStringThe unique meaning of Yandex Metrika cookies
fbc_cookie_idStringThe unique meaning of Facebook cookies
fbp_cookie_idStringThe unique meaning of Facebook cookies
offsetStringA service parameter of the Javascript SDK. Used to count sessions (the session table is only available in integration with DWH).