Repository URL to install this package:
|
Version:
1.3.0 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = startTracking;
var _effects = require('redux-saga/effects');
var _tagmanager = require('@doodle/tagmanager');
var _actions = require('../actions');
var _userHelper = require('../../helpers/userHelper');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _marked = /*#__PURE__*/_regenerator2.default.mark(onUserLoaded),
_marked2 = /*#__PURE__*/_regenerator2.default.mark(onFetchGeolocationSuccess),
_marked3 = /*#__PURE__*/_regenerator2.default.mark(onLocaleChange),
_marked4 = /*#__PURE__*/_regenerator2.default.mark(onShowActivationNotifications),
_marked5 = /*#__PURE__*/_regenerator2.default.mark(onClickResendActiviation),
_marked6 = /*#__PURE__*/_regenerator2.default.mark(watchUserLoaded),
_marked7 = /*#__PURE__*/_regenerator2.default.mark(watchFetchGeolocationSuccess),
_marked8 = /*#__PURE__*/_regenerator2.default.mark(watchLocaleChange),
_marked9 = /*#__PURE__*/_regenerator2.default.mark(watchShowActivationNotifications),
_marked10 = /*#__PURE__*/_regenerator2.default.mark(watchClickResendActiviation),
_marked11 = /*#__PURE__*/_regenerator2.default.mark(startTracking);
var defaultTrackingFields = {
event: 'gtmEvent',
eventNonInteraction: 'False',
eventLabel: undefined, // flush datalayer value in order to not mix them up between events
eventValue: undefined // flush datalayer value in order to not mix them up between events
};
function onUserLoaded(options, action) {
var user, lang;
return _regenerator2.default.wrap(function onUserLoaded$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
user = action.user;
_context.next = 3;
return (0, _effects.select)(function (state) {
return state.i18n.locale;
});
case 3:
lang = _context.sent;
_context.next = 6;
return (0, _effects.put)((0, _tagmanager.pushDataLayer)(_extends({}, (0, _userHelper.getUserAnalyticsData)(user, lang))));
case 6:
case 'end':
return _context.stop();
}
}
}, _marked, this);
}
function onFetchGeolocationSuccess(options) {
var geolocation;
return _regenerator2.default.wrap(function onFetchGeolocationSuccess$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return (0, _effects.select)(function (state) {
return state.geolocation.geolocation.country_code;
});
case 2:
geolocation = _context2.sent;
_context2.next = 5;
return (0, _effects.put)((0, _tagmanager.pushDataLayer)(_extends({}, (0, _userHelper.getGeolocationData)(geolocation))));
case 5:
case 'end':
return _context2.stop();
}
}
}, _marked2, this);
}
/**
* @todo move to web-i18n
*/
function onLocaleChange(options, action) {
return _regenerator2.default.wrap(function onLocaleChange$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return (0, _effects.put)((0, _tagmanager.pushDataLayer)({
language: action.payload.locale
}));
case 2:
case 'end':
return _context3.stop();
}
}
}, _marked3, this);
}
function onShowActivationNotifications() {
return _regenerator2.default.wrap(function onShowActivationNotifications$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _effects.put)((0, _tagmanager.pushDataLayer)(_extends({}, defaultTrackingFields, {
eventLabel: 'showActivationNotification'
})));
case 2:
case 'end':
return _context4.stop();
}
}
}, _marked4, this);
}
function onClickResendActiviation() {
return _regenerator2.default.wrap(function onClickResendActiviation$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return (0, _effects.put)((0, _tagmanager.pushDataLayer)(_extends({}, defaultTrackingFields, {
eventLabel: 'clickResendActivation'
})));
case 2:
case 'end':
return _context5.stop();
}
}
}, _marked5, this);
}
function watchUserLoaded(options) {
return _regenerator2.default.wrap(function watchUserLoaded$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return (0, _effects.takeEvery)(_actions.ActionTypes.USER_LOADED, onUserLoaded, options);
case 2:
case 'end':
return _context6.stop();
}
}
}, _marked6, this);
}
function watchFetchGeolocationSuccess(options) {
return _regenerator2.default.wrap(function watchFetchGeolocationSuccess$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return (0, _effects.takeEvery)('@doodle/geolocation/FETCH_GEOLOCATION_SUCCESS', onFetchGeolocationSuccess, options);
case 2:
case 'end':
return _context7.stop();
}
}
}, _marked7, this);
}
function watchLocaleChange(options) {
return _regenerator2.default.wrap(function watchLocaleChange$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return (0, _effects.takeEvery)('@doodle/i18n/CHANGE_LOCALE', onLocaleChange, options);
case 2:
case 'end':
return _context8.stop();
}
}
}, _marked8, this);
}
function watchShowActivationNotifications(options) {
return _regenerator2.default.wrap(function watchShowActivationNotifications$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return (0, _effects.takeEvery)(_actions.ActionTypes.RESEND_ACTIVATIONMAIL_ENABLED, onShowActivationNotifications, options);
case 2:
case 'end':
return _context9.stop();
}
}
}, _marked9, this);
}
function watchClickResendActiviation(options) {
return _regenerator2.default.wrap(function watchClickResendActiviation$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return (0, _effects.takeEvery)(_actions.ActionTypes.RESEND_ACTIVATIONMAIL, onClickResendActiviation, options);
case 2:
case 'end':
return _context10.stop();
}
}
}, _marked10, this);
}
function startTracking(options) {
return _regenerator2.default.wrap(function startTracking$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
_context11.next = 2;
return (0, _effects.all)([(0, _effects.call)(watchUserLoaded, options), (0, _effects.call)(watchFetchGeolocationSuccess, options), (0, _effects.call)(watchLocaleChange, options), (0, _effects.call)(watchShowActivationNotifications, options), (0, _effects.call)(watchClickResendActiviation, options)]);
case 2:
case 'end':
return _context11.stop();
}
}
}, _marked11, this);
}