Back to top

Retention Science - JavaScript Tracking

Getting Started

What is JavaScript used for?

JavaScript (JS) is used for event tracking in real-time. Google defines an event as "user interactions with content that can be tracked independently from a web page or a screen load."

By implementing our JS snippets on your webpages, you are able to track several standard events, as well as custom (user-defined) events on your webpages. These JS snippets should be inserted before the closing </head> tag of each page in which you are tracking an event.

How does Cortex use JavaScript tracking?

Retention Science's event tracking serves as the "food" for our AI models, enabling us to learn how users are engaging with your website and what types of campaigns/recommendations/subject lines will work best for them.

Whether you are using Shopify, Magento, or custom HTML scripts, this guide will help you understand our JavaScript event tracking and key details. (You can also watch our YouTube videos for similar explanations of data, JS, and other topics) 

How to Implement our JavaScript

  • Your tech stack will dictate how our JS should be implemented:
    • You may use Google Tag Manager to trigger our JS events if you can access the necessary key datapoints via data layer
    • If you have a Single-Page Application (e.g. Angular), you might want to create a new class for RS functionality
    • You can also add it under a <script> tag
  • The goal is to read through our JS documentation and determine how you should implement our pixel code; Your onboarding engineer/technical project manager will assist you in QAing your code.

How does ReSci Prioritize Site Performance?

Our JavaScript optimizes for your website performance by utilizing:

  1. Asynchronous script loading to ensure the script does not interfere with page loading or affect site speed.
  2. Content Delivery Network (CDN) hosting to ensure low latency and high data transfer speeds.
  3. Code encapsulation is an anonymous function so it does not interfere with any external JavaScript Variables.

User Interaction Events 101

JavaScript Events Overview

Events are user interactions with your website that are being tracked by our various JavaScript snippets. ReSci tracks a number of standard events by default. In addition to standard events, custom (user-defined) events are also supported.

All of the JS events work in a similar fashion, and share certain commonalities across the various events.

You can also read more about each specific event, as well as view code samples for each event on their respective pages listed below.

Standard JavaScript Events

Retention Science tracks the following events:

  1. Regular Page View
  2. Item Page View
  3. Add to Cart
  4. Shopping Cart View
  5. Checkout Success
  6. Checkout Success with Order Data
  7. Search (Optional)
  8. Email Capture (Optional)
  9. Custom Event (Optional)

Commonalities across all JS events

  • There is a static site ID that is always a string unique to your site, this will be provided during your Onboarding Kickoff call.
  • There is always an "if" condition to analyze if a user is logged in or not, and if they are you should add the user_id or email value in the wave as indicated in the code examples.
    • Only one is needed to ID the user.
    • We do cookie track users, so users that have browsed anonymously will have past actions associated automatically if they ever log in or click on an email and land onsite.
  • There is always a final "track" code line (static) which causes the event to be tracked.
  • There is always the immediately invoked function at the end of each script which is required for the JS tracking to work.

Generated by aglio on 11 Jun 2018