An example is below. You can use this on your site. The tracking calls are there simply as an example of how it would work. The first two calls would wait for Fanplayr to load, and the third would be called right away (given that Fanplayr is likely to have loaded within 2 seconds).
<script>
// You can use this code on your site to cache calls to Fanplayr before it has loaded.
// Note that "window.fanplayr_ready" should be defined before loading the Fanplayr JS
(function(){
var trackingCache = [];
var isReady = false;
// this is called when the Fanplayr platform is ready
window.fanplayr_ready = function(fanplayr, platform) {
isReady = true;
var i;
// track any cached tracking calls
for (i = 0; i < trackingCache.length; i++) {
fanplayr.reinitialize(trackingCache[i]);
}
trackingCache = [];
};
window.fanplayr_track = function(data) {
if (isReady) {
// track
window.fanplayr.reinitialize(data);
} else {
// cache this tracking call
trackingCache.push(data);
}
};
}());
</script>
<script>
// This script block is here to demo how tracking would work.
// Note the data itself is valid for the call but will not track anything.
window.fanplayr_track({
data: {}
});
window.fanplayr_track({
data: {}
});
setTimeout(function(){
window.fanplayr_track({
data: {}
});
}, 2000);
</script>
<!-- This is the script that you need to include AFTER setting the "window.fanplayr_ready" function -->
<script src="https://cdn.fanplayr.com/client/production/loader.js"></script>
The data is of the following format, and is the same as is set in normal page tracking.
// track the order using details in fp_sales_orderwindow.fanplayr.platform.trackOrder();// clears the current state, in case we make another order in the same sessionwindow.fanplayr.platform.state.clear()