Skip to content

Getting data from the FunnelFlux Javascript

The FunnelFlux JavaScript exposes data about the current visitor. You can read that data on the page instead of passing it in the URL.

When the script loads, it creates a hidden iframe with the id _ffq_track_.

That iframe posts a message to the parent page. A typical message looks like this. The live message is not pretty-printed:

window.parent.postMessage({
  "idHit": "325721182056347732",
  "hitTimestamp": 1529576310,
  "entranceTimestamp": 1529576310,
  "hitCost": 0,
  "idVisitor": "325721182056347732",
  "visitorTagIds": null,
  "idIncomingTraffic": "325721182056347732",
  "idTrafficSource": "17",
  "idFunnel": "203212058743938454",
  "idNode": 203744182158054903,
  "nodeType": 2,
  "timeOnPage": null,
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
  "mainLanguage": "en-US",
  "otherLanguages": null,
  "referrer": "",
  "bIsNewVisitor": true,
  "bFilteredTraffic": null,
  "bFunnelEntrance": true,
  "aTrackingFields": [],
  "frameId": "_ffq_track_",
  "ok": 1
}, '*');

The message carries the hit, visitor, funnel and node IDs, the visitor tag IDs, the tracking fields, and a few other fields such as idPage, nodesPath, mvt and trackingDomain. The visitor’s IP address is never included.

Listen for the message, then use the fields you need.

Put the listener before the FunnelFlux script. A listener that runs after the message has already been posted will miss it.

This reads the visitor ID:

<script type="text/javascript">
window.addEventListener("message", function(e) {
if( e.data.ok && e.data.frameId == '_ffq_track_' ) {
    var ffVisitorID = e.data.idVisitor;
}
}, false);
</script>

ffVisitorID is set from the tracking message when the page loads.

You can write the value into the page from the same listener. This fills a hidden form field whose id is visitorid, which is one way to pass the visitor ID into an email opt-in:

<script type="text/javascript">
window.addEventListener("message", function(e) {
if( e.data.ok && e.data.frameId == '_ffq_track_' ) {
    document.getElementById('visitorid').value = e.data.idVisitor;
}
}, false);
</script>

You can ask the script to include any token in the iframe message, then use that value in the page. Country name, device model, and ISP are typical cases, and you do not have to pass them on a redirect URL.

Add the tokens to fflux.track():

fflux.track({
   timeOnPage: false,
   timeOnPageResolution: 3000,
   noCookies: false,
   tokenInjection: {
     intoUrl: false,
     intoForms: { selector: null },
     intoLinks: { selector: null },
     tokens: {
       'country': '{location-countryname}',
       'isp': '{connection-isp}'
     }
   }
});

The postMessage payload then includes flux_inject with those tokens:

"flux_inject": {
    "intoUrl": false,
    "intoForms": {
        "selector": null
    },
    "intoLinks": {
        "selector": null
    },
    "tokens": {
        "country": "United States",
        "isp": "Comcast LLC"
    }
}

Read them the same way as the visitor ID:

<script type="text/javascript">
window.addEventListener("message", function(e) {
if( e.data.ok && e.data.frameId == '_ffq_track_' ) {
    var userCountry = e.data.flux_inject.tokens.country;
    var userIsp = e.data.flux_inject.tokens.isp;
}
}, false);
</script>

If the page text depends on these values, update the DOM inside that listener, after the variables are set. That keeps the updates in order, and it runs as soon as the message arrives.

The message itself does not carry location, device or connection details. To read them, request the matching tokens under tokens, as shown above. For the tokens you can use, see How to use FunnelFlux tokens.