Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
'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.watchInitAmplitude = watchInitAmplitude;
exports.watchLogAmplitudeEvent = watchLogAmplitudeEvent;
exports.watchSetAmplitudeUserId = watchSetAmplitudeUserId;
exports.watchSetAmplitudeUserProperties = watchSetAmplitudeUserProperties;
exports.watchUnsetAmplitudeUserProperty = watchUnsetAmplitudeUserProperty;
exports.watchRegenerateAmplitudeDeviceId = watchRegenerateAmplitudeDeviceId;
exports.default = amplitudeSaga;

var _amplitude = require('amplitude-js/amplitude');

var _amplitude2 = _interopRequireDefault(_amplitude);

var _effects = require('redux-saga/effects');

var _actions = require('../actions');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _marked = /*#__PURE__*/_regenerator2.default.mark(watchInitAmplitude),
    _marked2 = /*#__PURE__*/_regenerator2.default.mark(watchLogAmplitudeEvent),
    _marked3 = /*#__PURE__*/_regenerator2.default.mark(watchSetAmplitudeUserId),
    _marked4 = /*#__PURE__*/_regenerator2.default.mark(watchSetAmplitudeUserProperties),
    _marked5 = /*#__PURE__*/_regenerator2.default.mark(watchUnsetAmplitudeUserProperty),
    _marked6 = /*#__PURE__*/_regenerator2.default.mark(watchRegenerateAmplitudeDeviceId),
    _marked7 = /*#__PURE__*/_regenerator2.default.mark(amplitudeSaga);

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var propertyName = {
  eventType: 'Event Type'
};

function onInitAmplitude(options, action) {
  var amplitudeApiKey = options.amplitudeApiKey,
      dispatch = options.dispatch;

  function initCallback() {
    dispatch((0, _actions.initAmplitudeSuccess)());
  }
  // passing 2x null here since we don't pass the user ID with the init and don't need any aditional configuration for now
  _amplitude2.default.getInstance().init(amplitudeApiKey, null, null, initCallback);
}

function onLogAmplitudeEvent(options, action) {
  var _action$payload = action.payload,
      eventType = _action$payload.eventType,
      eventName = _action$payload.eventName,
      eventProperties = _action$payload.eventProperties,
      callback = _action$payload.callback;

  var eventProps = _extends({}, eventProperties, _defineProperty({}, propertyName.eventType, eventType));
  _amplitude2.default.getInstance().logEvent(eventName, eventProps, callback);
}

function onSetAmplitudeUserId(options, action) {
  var userId = action.userId;

  _amplitude2.default.getInstance().setUserId(userId);
}

function onSetAmplitudeUserProperties(options, action) {
  var _action$payload2 = action.payload,
      userProperties = _action$payload2.userProperties,
      once = _action$payload2.once;

  var identify = void 0;
  Object.keys(userProperties).forEach(function (key) {
    if (once) {
      identify = new _amplitude2.default.Identify().setOnce(key, userProperties[key]);
    } else {
      identify = new _amplitude2.default.Identify().set(key, userProperties[key]);
    }
    _amplitude2.default.getInstance().identify(identify);
  });
}

function onUnsetAmplitudeUserProperty(options, action) {
  var userProperty = action.userProperty;

  var identify = new _amplitude2.default.Identify().unset(userProperty);
  _amplitude2.default.getInstance().identify(identify);
}

function onRegenerateAmplitudeDeviceId() {
  _amplitude2.default.getInstance().regenerateDeviceId();
}

function watchInitAmplitude(options) {
  return _regenerator2.default.wrap(function watchInitAmplitude$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.INIT_AMPLITUDE, onInitAmplitude, options);

        case 2:
        case 'end':
          return _context.stop();
      }
    }
  }, _marked, this);
}

function watchLogAmplitudeEvent(options) {
  return _regenerator2.default.wrap(function watchLogAmplitudeEvent$(_context2) {
    while (1) {
      switch (_context2.prev = _context2.next) {
        case 0:
          _context2.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.LOG_AMPLITUDE_EVENT, onLogAmplitudeEvent, options);

        case 2:
        case 'end':
          return _context2.stop();
      }
    }
  }, _marked2, this);
}

function watchSetAmplitudeUserId(options) {
  return _regenerator2.default.wrap(function watchSetAmplitudeUserId$(_context3) {
    while (1) {
      switch (_context3.prev = _context3.next) {
        case 0:
          _context3.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.SET_AMPLITUDE_USER_ID, onSetAmplitudeUserId, options);

        case 2:
        case 'end':
          return _context3.stop();
      }
    }
  }, _marked3, this);
}

function watchSetAmplitudeUserProperties(options) {
  return _regenerator2.default.wrap(function watchSetAmplitudeUserProperties$(_context4) {
    while (1) {
      switch (_context4.prev = _context4.next) {
        case 0:
          _context4.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.SET_AMPLITUDE_USER_PROPERTIES, onSetAmplitudeUserProperties, options);

        case 2:
        case 'end':
          return _context4.stop();
      }
    }
  }, _marked4, this);
}

function watchUnsetAmplitudeUserProperty(options) {
  return _regenerator2.default.wrap(function watchUnsetAmplitudeUserProperty$(_context5) {
    while (1) {
      switch (_context5.prev = _context5.next) {
        case 0:
          _context5.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.UNSET_AMPLITUDE_USER_PROPERTY, onUnsetAmplitudeUserProperty, options);

        case 2:
        case 'end':
          return _context5.stop();
      }
    }
  }, _marked5, this);
}

function watchRegenerateAmplitudeDeviceId(options) {
  return _regenerator2.default.wrap(function watchRegenerateAmplitudeDeviceId$(_context6) {
    while (1) {
      switch (_context6.prev = _context6.next) {
        case 0:
          _context6.next = 2;
          return (0, _effects.takeEvery)(_actions.ActionTypes.REGENERATE_AMPLITUDE_DEVICE_ID, onRegenerateAmplitudeDeviceId, options);

        case 2:
        case 'end':
          return _context6.stop();
      }
    }
  }, _marked6, this);
}

function amplitudeSaga() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return _regenerator2.default.wrap(function amplitudeSaga$(_context7) {
    while (1) {
      switch (_context7.prev = _context7.next) {
        case 0:
          _context7.next = 2;
          return (0, _effects.all)([(0, _effects.call)(watchInitAmplitude, options), (0, _effects.call)(watchLogAmplitudeEvent, options), (0, _effects.call)(watchSetAmplitudeUserId, options), (0, _effects.call)(watchSetAmplitudeUserProperties, options), (0, _effects.call)(watchUnsetAmplitudeUserProperty, options), (0, _effects.call)(watchRegenerateAmplitudeDeviceId, options)]);

        case 2:
        case 'end':
          return _context7.stop();
      }
    }
  }, _marked7, this);
}