Esempio n. 1
0
Amplitude.prototype._format = function(track){
  var options = track.options(this.name);

  var properties = {
    user_id              : track.userId(),
    event_type           : track.event(),
    device_id            : track.proxy('context.device.id'),
    time                 : track.timestamp().getTime(),
    event_properties     : customProperties(track.properties()),
    user_properties      : track.traits(),
    client_sdk           : track.proxy('context.os.name'),
    app_version          : track.proxy('context.app.version'),
    client_os            : track.proxy('context.os.version'),
    device_type          : track.proxy('context.device.type'),
    device_carrier       : track.proxy('context.network.carrier'),
    country              : track.proxy('context.location.country'),
    language             : track.proxy('context.language'),
    revenue              : track.revenue(),
    location_lat         : track.proxy('context.location.latitude'),
    location_lng         : track.proxy('context.location.longitude'),
    ip                   : track.ip(),
    event_id             : find(options, 'event_id'),
    amplitude_event_type : find(options, 'event_type')
  };

  return properties;
}
Esempio n. 2
0
exports.identify = function(identify){
  var payload = common(identify);
  del(payload, 'amplitude_event_type');
  del(payload, 'session_id');
  del(payload, 'event_id');
  payload.paying = find(identify.options('Amplitude'), 'paying');
  payload.start_version = find(identify.options('Amplitude'), 'start_version');
  return payload;
};
Esempio n. 3
0
Facade.prototype.options = function(integration) {
  var obj = this.obj.options || this.obj.context || {};
  var options = this.opts.clone ? clone(obj) : obj;
  if (!integration) return options;
  if (!this.enabled(integration)) return;
  var integrations = this.integrations();
  var value = integrations[integration] || objCase(integrations, integration);
  if (typeof value !== 'object') value = objCase(this.options(), integration);
  return typeof value === 'object' ? value : {};
};
Esempio n. 4
0
function formatCompany (company) {
  if (is.string(company)) company = { name : company };
  var created = dot(company, 'created') || dot(company, 'createdAt');
  if (created) company.created_at = time(created);
  if (!company.id && !company.name) return company;
  company.id = company.id || hash(company.name);
  dot.del(company, 'created');
  delete company.createdAt;
  return company;
}
Esempio n. 5
0
function common(facade){
  var options = facade.options('Amplitude');
  var os = facade.proxy('context.os.name');
  var ret = {
    user_id: facade.userId(),
    device_id: facade.proxy('context.device.id') || facade.anonymousId(),
    time: facade.timestamp().getTime(),
    app_version: facade.proxy('context.app.version'),
    platform: facade.proxy('context.library.name'),
    os_name: os,
    os_version: facade.proxy('context.os.version'),
    carrier: facade.proxy('context.network.carrier'),
    device_model: facade.proxy('context.device.model'),
    device_brand: facade.proxy('context.device.brand'),
    device_manufacturer: facade.proxy('context.device.manufacturer'),
    location_lat: facade.proxy('context.location.latitude'),
    location_lng: facade.proxy('context.location.longitude'),
    ip: facade.ip(),
    amplitude_event_type: find(options, 'event_type'),
    session_id: find(options, 'session_id'),
    event_id: find(options, 'event_id')
  };

  var loc = locale(facade);
  if (loc) {
    ret.language = loc.language;
    ret.country = loc.country;
  }

  if (facade.country()) ret.country = facade.country();
  if (facade.city()) ret.city = facade.city();
  if (facade.region()) ret.region = facade.region();

  if (os && os.toLowerCase() == 'ios') {
      ret.idfa = facade.proxy('device.idfa');
  } else if (os && os.toLowerCase() == 'android') {
      //Older segment clients sent idfa, newer ones send advertisingId
      ret.adid = facade.proxy('device.idfa');
      if(!ret.adid) {
        ret.adid = facade.proxy('device.advertisingId');
      }
  }

  ret.user_properties = traits(facade.traits());

  return reject(ret);
}
Esempio n. 6
0
Identify.prototype.age = function() {
  var date = this.birthday();
  var age = get(this.traits(), 'age');
  if (age != null) return age;
  if (type(date) !== 'date') return;
  var now = new Date();
  return now.getFullYear() - date.getFullYear();
};
Esempio n. 7
0
function common(facade){
  var options = facade.options('Amplitude');
  return {
    user_id: facade.userId(),
    device_id: facade.proxy('context.device.id'),
    time: facade.timestamp().getTime(),
    user_properties: facade.traits(),
    client_sdk: facade.proxy('context.os.name'),
    app_version: facade.proxy('context.app.version'),
    client_os: facade.proxy('context.os.version'),
    device_type: device(facade),
    device_carrier: facade.proxy('context.network.carrier'),
    country: facade.proxy('context.location.country'),
    language: facade.proxy('context.language'),
    location_lat: facade.proxy('context.location.latitude'),
    location_lng: facade.proxy('context.location.longitude'),
    ip: facade.ip(),
    event_id: find(options, 'event_id'),
    amplitude_event_type: find(options, 'event_type')
  };
}
Esempio n. 8
0
Facade.prototype.proxy = function(field) {
  var fields = field.split('.');
  field = fields.shift();

  // Call a function at the beginning to take advantage of facaded fields
  var obj = this[field] || this.field(field);
  if (!obj) return obj;
  if (typeof obj === 'function') obj = obj.call(this) || {};
  if (fields.length === 0) return this.opts.clone ? transform(obj) : obj;

  obj = objCase(obj, fields.join('.'));
  return this.opts.clone ? transform(obj) : obj;
};
Esempio n. 9
0
function common(facade){
  var options = facade.options('Amplitude');
  var ret = {
    user_id: facade.userId(),
    device_id: facade.proxy('context.device.id') || facade.anonymousId(),
    time: facade.timestamp().getTime(),
    app_version: facade.proxy('context.app.version'),
    platform: facade.proxy('context.library.name'),
    os_name: facade.proxy('context.os.name'),
    os_version: facade.proxy('context.os.version'),
    carrier: facade.proxy('context.network.carrier'),
    device_model: facade.proxy('context.device.model'),
    device_brand: facade.proxy('context.device.brand'),
    device_manufacturer: facade.proxy('context.device.manufacturer'),
    location_lat: facade.proxy('context.location.latitude'),
    location_lng: facade.proxy('context.location.longitude'),
    ip: facade.ip(),
    amplitude_event_type: find(options, 'event_type'),
    session_id: find(options, 'session_id'),
    event_id: find(options, 'event_id')
  };

  var loc = locale(facade);

  if (loc) {
    ret.language = loc.language;
    ret.country = loc.country;
  }

  if (facade.country()) ret.country = facade.country();
  if (facade.city()) ret.city = facade.city();
  if (facade.region()) ret.region = facade.region();

  ret.user_properties = traits(facade.traits());

  return reject(ret);
}
function metrics(obj, data){
  var dimensions = data.dimensions;
  var metrics = data.metrics;
  var names = keys(metrics).concat(keys(dimensions));
  var ret = {};

  for (var i = 0; i < names.length; ++i) {
    var name = names[i];
    var key = metrics[name] || dimensions[name];
    var value = dot(obj, name);
    if (null == value) continue;
    ret[key] = value;
  }

  return ret;
}
Esempio n. 11
0
function metrics(obj, data){
  var dimensions = data.dimensions || {};
  var metrics = data.metrics || {};
  var names = Object.keys(metrics).concat(Object.keys(dimensions));
  var ret = {};

  for (var i = 0; i < names.length; ++i) {
    var name = names[i];
    var key = metrics[name] || dimensions[name];
    var value = lookup(obj, name) || obj[name];
    if (null == value) continue;
    if (key = shorten(key)) ret[key] = value;
  }

  return ret;
}
Esempio n. 12
0
Track.prototype.subtotal = function() {
  var subtotal = get(this.properties(), 'subtotal');
  var total = this.total() || this.revenue();

  if (subtotal) return subtotal;
  if (!total) return 0;

  if (this.total()) {
    var n = this.tax();
    if (n) total -= n;
    n = this.shipping();
    if (n) total -= n;
    n = this.discount();
    if (n) total += n;
  }

  return total;
};
Esempio n. 13
0
Drip.prototype.campaignId = function(msg, settings){
  var opts = msg.options(this.name) || {};
  return settings.campaignId || find(opts, 'campaignId');
};
Esempio n. 14
0
Track.prototype.products = function() {
  var props = this.properties();
  var products = get(props, 'products');
  return type(products) === 'array' ? products : [];
};
Esempio n. 15
0
Identify.prototype.position = function() {
  var traits = this.traits();
  return get(traits, 'position') || get(traits, 'jobTitle');
};
Esempio n. 16
0
Identify.prototype.avatar = function() {
  var traits = this.traits();
  return get(traits, 'avatar') || get(traits, 'photoUrl') || get(traits, 'avatarUrl');
};