Repository URL to install this package:
|
Version:
0.12.1 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getOnLogAmplitudeEventCallback = getOnLogAmplitudeEventCallback;
exports.getOnLogAmplitudeisSameTabLinkEventCallback = getOnLogAmplitudeisSameTabLinkEventCallback;
var _actions = require('../actions');
var CALLBACK_TIMEOUT_IN_MS = 1000;
/**
* Returns a function that is used as a callback for logging amplitude events
* It will either dispatch a success action or an error action
* @return {function}
*/
function getOnLogAmplitudeEventCallback(dispatch, eventName, eventProps) {
var logEventCallback = function logEventCallback(status, response) {
if (status === 200 && response === 'success') {
dispatch((0, _actions.logAmplitudeEventSuccess)(eventName, eventProps));
} else {
dispatch((0, _actions.logAmplitudeEventError)(eventName, eventProps));
}
};
return logEventCallback;
}
/**
* Returns a function that is used as a callback for logging amplitude events
* It will either dispatch and event succssess action or it will timeout after CALLBACK_TIMEOUT_IN_MS and trigger an error action
* This is needed to make sure that we don't let users wait too long incase we want to track links that redirect in the same window/tab
* @return {function}
*/
function getOnLogAmplitudeisSameTabLinkEventCallback(dispatch, eventName, eventProps) {
var logEventisSameTabLinkCallback = function logEventisSameTabLinkCallback(status, response) {
var eventTimedOut = void 0;
function timeoutCallback() {
eventTimedOut = true;
dispatch((0, _actions.logAmplitudeEventError)(eventName, eventProps));
}
var eventCallbackTimout = setTimeout(timeoutCallback, CALLBACK_TIMEOUT_IN_MS);
if (status === 200 && response === 'success' && !eventTimedOut) {
clearTimeout(eventCallbackTimout);
dispatch((0, _actions.logAmplitudeEventSuccess)(eventName, eventProps));
}
};
return logEventisSameTabLinkCallback;
}