src/analytics.js
// The callback is always called, analytics is optional.
The callback is always called, analytics is optional.
The callback is always called analytics is optional .
function init(callback, context) {
	if (typeof endpoint !== 'string') {
		endpoint = null;
		console.warn('Analytics is not configured.');
		callback.call(context);
		return;
	}
	if (typeof playerKey !== 'undefined') {
		callback.call(context);
		return;
	}
	if (persist.hasLocalStorage) {
		var key = window.localStorage.getItem('key');
		if (key !== null) {
			playerKey = key;
			callback.call(context);
			return;
		}
	}
	var xhr = new XMLHttpRequest();
	xhr.open('POST', endpoint + 'player', true);
	xhr.timeout = 15 * 1000;
	xhr.onreadystatechange = function() {
		if (xhr.readyState !== 4) {
			return;
		}
		var key;
		if (xhr.status == 200) {
			var data;
			try {
				data = JSON.parse(xhr.responseText);
				key = data.Player;
			} catch (e) {
			}
		}
		if (typeof key == 'string') {
			playerKey = key;
			if (persist.hasLocalStorage) {
				window.localStorage.setItem('key', key);
			}
		} else {
			playerKey = null;
		}
		callback.call(context);
	};
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.send(JSON.stringify({
		Referrer: document.referrer,
		IFrame: isIFrame(),
	}));
}
function init ( callback , context ) { if ( typeof endpoint !== 'string' ) { endpoint = null ; console . warn ( 'Analytics is not configured.' ) ; callback . call ( context ) ; return ; } if ( typeof playerKey !== 'undefined' ) { callback . call ( context ) ; return ; } if ( persist . hasLocalStorage ) { var key = window . localStorage . getItem ( 'key' ) ; if ( key !== null ) { playerKey = key ; callback . call ( context ) ; return ; } } var xhr = new XMLHttpRequest ( ) ; xhr . open ( 'POST' , endpoint + 'player' , true ) ; xhr . timeout = 15 * 1000 ; xhr . onreadystatechange = function ( ) { if ( xhr . readyState !== 4 ) { return ; } var key ; if ( xhr . status == 200 ) { var data ; try { data = JSON . parse ( xhr . responseText ) ; key = data . Player ; } catch ( e ) { } } if ( typeof key == 'string' ) { playerKey = key ; if ( persist . hasLocalStorage ) { window . localStorage . setItem ( 'key' , key ) ; } } else { playerKey = null ; } callback . call ( context ) ; } ; xhr . setRequestHeader ( 'Content-Type' , 'application/json' ) ; xhr . send ( JSON . stringify ( { Referrer : document . referrer , IFrame : isIFrame ( ) , } ) ) ; }
The callback is always called, analytics is optional.
The callback is always called analytics is optional .