OutboundFormTracker.prototype.handleFormSubmits = function(event, form) {

  var action = parseUrl(form.action).href;
  var defaultFields = {
    transport: 'beacon',
    eventCategory: 'Outbound Form',
    eventAction: 'submit',
    eventLabel: action
  };

  if (this.opts.shouldTrackOutboundForm(form, parseUrl)) {

    if (!navigator.sendBeacon) {
      // Stops the submit and waits until the hit is complete (with timeout)
      // for browsers that don't support beacon.
      event.preventDefault();
      defaultFields.hitCallback = withTimeout(function() {
        form.submit();
      });
    }

    var userFields = assign({}, this.opts.fieldsObj,
        getAttributeFields(form, this.opts.attributePrefix));

    this.tracker.send('event', createFieldsObj(
        defaultFields, userFields, this.tracker, this.opts.hitFilter, form));
  }
};
Exemplo n.º 2
0
CleanUrlTracker.prototype.cleanUrlTask = function(model) {

  var location = model.get('location');
  var page = model.get('page');
  var url = parseUrl(page || location);

  var oldPath = url.pathname;
  var newPath = oldPath;

  // If an index filename was provided, remove it if it appears at the end
  // of the URL.
  if (this.opts.indexFilename) {
    var parts = newPath.split('/');
    if (this.opts.indexFilename == parts[parts.length - 1]) {
      parts[parts.length - 1] = '';
      newPath = parts.join('/');
    }
  }

  // Ensure the URL ends with or doesn't end with slash based on the
  // `trailingSlash` option. Note that filename URLs should never contain
  // a trailing slash.
  if (this.opts.trailingSlash == 'remove') {
      newPath = newPath.replace(/\/+$/, '');
  }
  else if (this.opts.trailingSlash == 'add') {
    var isFilename = /\.\w+$/.test(newPath);
    if (!isFilename && newPath.substr(-1) != '/') {
      newPath = newPath + '/';
    }
  }

  // If a query dimensions index was provided, set the query string portion
  // of the URL on that dimension. If no query string exists on the URL use
  // the NULL_DIMENSION.
  if (this.opts.stripQuery && this.opts.queryDimensionIndex) {
    model.set('dimension' + this.opts.queryDimensionIndex,
        url.query || constants.NULL_DIMENSION, true);
  }

  model.set('page', newPath + (!this.opts.stripQuery ? url.search : ''), true);
};