1. Home
  2. Docs
  3. Developer Guide
  4. How to add Flexie tracking code in your website

How to add Flexie tracking code in your website

Adding Flexie Tracking code in your website, its pretty straightforward, You can just copy the code below and insert into your website template. It mostly reside in the head which is included from all the other templates.

If you are looking for custom events, you can call the FlexieSDK.trackPageHit() anywhere in your website, once the FlexieSDK is loaded it can be accessed from anywhere.

You can have different use cases, but most probably you just want to record the Leads or Contacts history on your website, and then take specific actions from Workflow based on their Activity in specific sections of your website.

<script type="text/javascript">
    if (typeof FlexieSDKLoaded == 'undefined') {
        var FlexieSDKLoaded = true;
        window.FlexieDomain = 'https://{Your Flexie Instance}';
        var head            = document.getElementsByTagName('head')[0];
        var script          = document.createElement('script');
        script.type         = 'text/javascript';
        script.src          = 'https://{Your Flexie Instance}/media/js/flexie.js?1.5';
        script.onload       = function() {
            // The trackPageHit method can be used everywhere in your code once the
            // FlexieSDK is loaded, you can also keep the tracking data in Cookie,
            // So you dont have to set any parameter to the trackPageHit method.
                hitEvent: 'pageview',
                identifierAlias: 'email',
                identifierValue: 'your@email.com'
            // If you dont pass any params to the trackPageHit method,
            // it would look on cookies under the track_fx key, and then
            // all data would be taken from there if the object is set properly.
            // Object format in the cookie must be a valid JSON object like:
            // {
            //    hitEvent: 'pageview',
            //    identifierAlias: 'email',
            //    identifierValue: 'your@email.com',
            //    isSecure: true/false
            // }
            // You can also set the Cookie from somewhere else in your code,
            // Based on your visitor behaviour. You can do it using our build-in
            // methods from the FlexieSDK.
            // Setter - Cookies.set('track_fx', trackData, { expires: 1200, secure: true });
            // Getter - Cookies.getJSON('track_fx');

    } else {

As you can see from the comments in the code, you can set what to track, or you can use the already set Cookies from which the tracking code is smart enough to understand who is the Lead or Contact which is browsing your website.

This code can detect cookies, if previously set by some actions in your website and if they are set as the standard described in the code comments above. Typically the cookie is set by a form submission or something else you may have in your website.

Something to Note is that Flexie CRM would track known visitors only, which might be a Lead or a Contact, it won’t collect unknown data, because you don’t really need them, unless you are monitoring the performance of your website content, and in this case, it’s outside the “scope” of Flexie CRM.

You can use the hitEvent, which is very handy, to track literally anything done into your website, for instance, you can track your youtube video being played or stoped or even paused. This way you can have a better picture on what is your lead doing on your website, and of course, based on this tracking data you can take specific actions.


// The player variable is your youtube player instance
// you have embed in your website, so you are listening on the 
// player events and then track the lead activity.
player.addEventListener("onPlayerStateChange", function(event){
    // Track when lead clicks to Play,
    // hitEvent value could be anything which describe
    // the action and the video being played
    if (event.data == player.PlayerState.PLAYING) {
            hitEvent: 'YOUTUBE_VIDEO_PLAY'


As you can see, the Flexie.trackPageHit() method can be used everywhere and its very practical to use in any scenario you may have.

To stay updated with the latest features, news and how-to articles and videos, please join our group on Facebook, Flexie CRM Academy.

How can we help?