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    
@doodle/tracking / dist / esm / src / core / validators.js
Size: Mime:
/**
 * Validates tracking calls
 *
 * @param {TrackingDefinitionData} trackingData The data that needs to be tracked
 * @return {Array.<Error>}
 */
const validateTrackingData = ({
  track,
  page,
  identify
}) => {
  const errors = []; // Validate mandatory fields for Track API

  if (track) {
    if (!track.event) {
      errors.push('track.event');
    }

    if (!track.properties || !track.properties.category) {
      errors.push('track.properties.category');
    }
  } // Validate mandatory fields for Page API


  if (page) {
    if (!page.name) {
      errors.push('page.name');
    }

    if (!page.properties || !page.properties.path) {
      errors.push('page.properties.path');
    }

    if (!page.properties || !page.properties.title) {
      errors.push('page.properties.title');
    }

    if (!page.properties || !page.properties.url) {
      errors.push('page.properties.url');
    }
  } // Validate mandatory fields for Identify API


  if (identify) {
    if (!identify.userId) {
      errors.push('identify.userId');
    }
  }

  return errors;
};

export { validateTrackingData };
//# sourceMappingURL=validators.js.map