Vous êtes sur la page 1sur 3

Moat

Infinite Scroll API Documentation


Use the Moat infinite scroll API to control what to track on an
infinite scroll page via a callback on the page.

1. Set up: window.onMISReady(api)

This should be setup in the top window so that it triggers on load prior
to the moatcontent.js header tag firing

If your Moat content tag has been configured to use the infinite scroll
API, it expects a callback called window.onMISReady to be present on
the page. When this function is called, a reference to the API object will
be passed as a parameter, indicating that the API is ready for use.

A sample implementation is below but please do not cut and paste as


you may need to configure to your site.

Set up window.onMISReady: the specific implementation is up to you.


Here is a basic example:
var moatApi;
window.onMISReady = function (api) {
moatApi = api;
// do something with API
}

2. Setup Tracking: Now that you have the function defined, you
will need to send us specific tracking for an element or css
query selector that is part of the infinite scroll. You can add
this where you intend to pass the article to track.
Note: if your first article needs infinite scroll tracking, please be sure
to call track in the function right away.

Usage: moatApi.track(element[, options])
This function tells Moat content tag to trigger a new page view and
start tracking the article’s metrics (e.g. page dwell time, scroll depth,
scroll velocity) represented by element. I.e. when the article changes,
fire the moatApi.track function.

Parameters
element – must be a DOM element or a string that is a CSS query
selector. For accurate tracking, its dimensions must match the entirety
of the article.

options – object – The page view configuration.


resumeTracking – boolean – This controls the behavior when an article


that has already been viewed is returned to. If true, then the page view
is “resumed”. If false, a new page view will be triggered.
The default value is true.

levels – Array – An array of levels for the page view. Our content tag
tracks level 1 as domain, level 2 as title and level 3 as URL . An example
of what to send is below but could vary on your site so please adjust
accordingly.

Example of Implementation On Page 3:


This example will track article and trigger a new page view even if the
article has previously been tracked. If resumeTracking were true, this
would only trigger a new page view if article was being tracked for the
first time. Please note that article in the example below should be a
DOM element or string for CSS query selector.



function trackApi(moatApi, domain_name, _title) {
moatApi.track(article, {
resumeTracking: false,
levels: [
domain_name, // get hostname
_title, //get title
'__page__', // This exact string should be passed in. It
is a macro that will be replaced with the URL of the page.
'-'
]
});
}

var domain_name = window.location.hostname;


var title = getTitle();
if (moatApi) {
trackApi(moatApi, domain_name, _title);
} else {
window.onMISReady = function(api) {
moatApi = api;
trackApi(moatApi, domain_name, _title);
}
}

Note:
- There are two places you most likely want to call track. The first is in
the place in your code where you load a new article. The second is
inside the onMISReady callback itself, to make sure the first article is
tracked right away
- You also need to initialize window.onMISReady as a function on the
top window as shown on page 1.

Vous aimerez peut-être aussi