<commit_before>import Integration from './../Integration.js';
import deleteProperty from './../functions/deleteProperty.js';
import {
  VIEWED_PAGE,
  VIEWED_PRODUCT_DETAIL,
  VIEWED_PRODUCT_LISTING,
  SEARCHED_PRODUCTS,
  VIEWED_CART,
  COMPLETED_TRANSACTION,
} from './../events';

const SEMANTIC_EVENTS = [
  VIEWED_PAGE,
  VIEWED_PRODUCT_DETAIL,
  VIEWED_PRODUCT_LISTING,
  SEARCHED_PRODUCTS,
  VIEWED_CART,
  COMPLETED_TRANSACTION,
];

function lineItemsToProductIds(lineItems) {
  lineItems = lineItems || [];
  const productIds = lineItems.filter((lineItem) => {
    return !!(lineItem.product.id || lineItem.product.skuCode);
  }).map((lineItem) => {
    return lineItem.product.id || lineItem.product.skuCode;
  });
  return productIds;
}

class GoogleAdWords extends Integration {

  constructor(digitalData, options) {
    const optionsWithDefaults = Object.assign({
      conversionId: '',
      remarketingOnly: false,
    }, options);

    super(digitalData, optionsWithDefaults);

    this.addTag({
      type: 'script',
      attr: {
        src: '//www.googleadservices.com/pagead/conversion_async.js',
      },
    });
  }

  getSemanticEvents() {
    return SEMANTIC_EVENTS;
  }

  getEnrichableEventProps(event) {
    let enrichableProps = [];
    switch (event.name) {
    case VIEWED_PAGE:
      enrichableProps = [
        'page.type',
      ];
      break;
    case VIEWED_PRODUCT_DETAIL:
      enrichableProps = [
        'product',
      ];
      break;
    case VIEWED_PRODUCT_LISTING:
      enrichableProps = [
        'listing.category',
      ];
      break;
    case VIEWED_CART:
      enrichableProps = [
        'cart',
      ];
      break;
    case COMPLETED_TRANSACTION:
      enrichableProps = [
        'transaction',
      ];
      break;
    default:
      // do nothing
    }

    return enrichableProps;
  }

  getEventValidationConfig(event) {
    const config = {
      [VIEWED_PAGE]: {
        fields: ['page.type'],
        validations: {
          'page.type': {
            errors: ['required', 'string'],
          },
        },
      },
      [VIEWED_PRODUCT_DETAIL]: {
        fields: [
          'product.id',
          'product.unitSalePrice',
          'product.category',
        ],
        validations: {
          'product.id': {
            errors: ['required'],
            warnings: ['string'],
          },
          'product.unitSalePrice': {
            warnings: ['required', 'numeric'],
          },
          'product.category': {
            warnings: ['required', 'array'],
          },
        },
        [VIEWED_PRODUCT_LISTING]: {
          fields: ['listing.category'],
          validations: {
            'listing.category': {
              errors: ['required'],
              warnings: ['array'],
            },
          },
        },
        [VIEWED_CART]: {
          fields: ['cart.subtotal', 'cart.lineItems[].product.id'],
          validations: {
            'cart.subtotal': {
              errors: ['required'],
              warnings: ['string'],
            },
            'cart.lineItems[].product.id': {
              errors: ['required'],
              warnings: ['string'],
            },
          },
        },
        [COMPLETED_TRANSACTION]: {
          fields: ['transaction.subtotal', 'transaction.lineItems[].product.id'],
          validations: {
            'transaction.subtotal': {
              errors: ['required'],
              warnings: ['string'],
            },
            'transaction.lineItems[].product.id': {
              errors: ['required'],
              warnings: ['string'],
            },
          },
        },
      },
    };

    return config[event.name];
  }

  initialize() {
    this.asyncQueue = [];<commit_msg>AdWords validation fix<commit_after>import Integration from './../Integration.js';
import deleteProperty from './../functions/deleteProperty.js';
import {
  VIEWED_PAGE,
  VIEWED_PRODUCT_DETAIL,
  VIEWED_PRODUCT_LISTING,
  SEARCHED_PRODUCTS,
  VIEWED_CART,
  COMPLETED_TRANSACTION,
} from './../events';

const SEMANTIC_EVENTS = [
  VIEWED_PAGE,
  VIEWED_PRODUCT_DETAIL,
  VIEWED_PRODUCT_LISTING,
  SEARCHED_PRODUCTS,
  VIEWED_CART,
  COMPLETED_TRANSACTION,
];

function lineItemsToProductIds(lineItems) {
  lineItems = lineItems || [];
  const productIds = lineItems.filter((lineItem) => {
    return !!(lineItem.product.id || lineItem.product.skuCode);
  }).map((lineItem) => {
    return lineItem.product.id || lineItem.product.skuCode;
  });
  return productIds;
}

class GoogleAdWords extends Integration {

  constructor(digitalData, options) {
    const optionsWithDefaults = Object.assign({
      conversionId: '',
      remarketingOnly: false,
    }, options);

    super(digitalData, optionsWithDefaults);

    this.addTag({
      type: 'script',
      attr: {
        src: '//www.googleadservices.com/pagead/conversion_async.js',
      },
    });
  }

  getSemanticEvents() {
    return SEMANTIC_EVENTS;
  }

  getEnrichableEventProps(event) {
    let enrichableProps = [];
    switch (event.name) {
    case VIEWED_PAGE:
      enrichableProps = [
        'page.type',
      ];
      break;
    case VIEWED_PRODUCT_DETAIL:
      enrichableProps = [
        'product',
      ];
      break;
    case VIEWED_PRODUCT_LISTING:
      enrichableProps = [
        'listing.category',
      ];
      break;
    case VIEWED_CART:
      enrichableProps = [
        'cart',
      ];
      break;
    case COMPLETED_TRANSACTION:
      enrichableProps = [
        'transaction',
      ];
      break;
    default:
      // do nothing
    }

    return enrichableProps;
  }

  getEventValidationConfig(event) {
    const config = {
      [VIEWED_PAGE]: {
        fields: ['page.type'],
        validations: {
          'page.type': {
            errors: ['required', 'string'],
          },
        },
      },
      [VIEWED_PRODUCT_DETAIL]: {
        fields: [
          'product.id',
          'product.unitSalePrice',
          'product.category',
        ],
        validations: {
          'product.id': {
            errors: ['required'],
            warnings: ['string'],
          },
          'product.unitSalePrice': {
            warnings: ['required', 'numeric'],
          },
          'product.category': {
            warnings: ['required', 'array'],
          },
        },
      },
      [VIEWED_PRODUCT_LISTING]: {
        fields: ['listing.category'],
        validations: {
          'listing.category': {
            errors: ['required'],
            warnings: ['array'],
          },
        },
      },
      [VIEWED_CART]: {
        fields: ['cart.subtotal', 'cart.lineItems[].product.id'],
        validations: {
          'cart.subtotal': {
            errors: ['required'],
            warnings: ['numeric'],
          },
          'cart.lineItems[].product.id': {
            errors: ['required'],
            warnings: ['string'],
          },
        },
      },
      [COMPLETED_TRANSACTION]: {
        fields: ['transaction.subtotal', 'transaction.lineItems[].product.id'],
        validations: {
          'transaction.subtotal': {
            errors: ['required'],
            warnings: ['numeric'],
          },
          'transaction.lineItems[].product.id': {
            errors: ['required'],
            warnings: ['string'],
          },
        },
      },
    };

    return config[event.name];
  }

  initialize() {
    this.asyncQueue = [];
{'fraction_non_alphanumeric': 0.13879531060503975, 'fraction_numerical': 0.0, 'mean_word_length': 1.8958252048380804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3377877', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2221, 'n_words': 348}