/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	// The require scope
/******/ 	var __webpack_require__ = {};
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/global */
/******/ 	(() => {
/******/ 		__webpack_require__.g = (function() {
/******/ 			if (typeof globalThis === 'object') return globalThis;
/******/ 			try {
/******/ 				return this || new Function('return this')();
/******/ 			} catch (e) {
/******/ 				if (typeof window === 'object') return window;
/******/ 			}
/******/ 		})();
/******/ 	})();
/******/ 	
/************************************************************************/
/*!*********************************************************!*\
  !*** ./js/event-providers/optin-monster.js + 1 modules ***!
  \*********************************************************/

;// ./js/event-providers/utils.js
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * Utilities for conversion tracking event providers.
 *
 * Site Kit by Google, Copyright 2025 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// PII types for classification.
const PII_TYPE = {
  EMAIL: 'email',
  PHONE: 'phone',
  NAME: 'name'
};

// Indicators for identifying PII fields.
const PII_INDICATORS = {
  [PII_TYPE.EMAIL]: ['email', 'e-mail', 'mail', 'email address'],
  [PII_TYPE.PHONE]: ['phone', 'tel', 'mobile', 'cell', 'telephone', 'phone number'],
  [PII_TYPE.NAME]: ['name', 'full-name', 'full name', 'full_name', 'fullname', 'first-name', 'first name', 'first_name', 'firstname', 'last-name', 'last name', 'last_name', 'lastname', 'given-name', 'given name', 'given_name', 'givenname', 'family-name', 'family name', 'family_name', 'familyname', 'fname', 'lname', 'first', 'last', 'your-name', 'your name']
};
const PHONE_MIN_DIGIT_COUNT = 7;

/**
 * Normalizes a value for use in conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to normalize.
 * @return {string} The normalized value.
 */
function normalizeValue(value) {
  if (!value || typeof value !== 'string') {
    return '';
  }
  return value.trim().toLowerCase();
}

/**
 * Normalizes a label by removing common form suffixes and prefixes.
 *
 * @since 1.162.0
 *
 * @param {string} label The label to normalize.
 * @return {string} The normalized label.
 */
function normalizeLabel(label) {
  if (!label || typeof label !== 'string') {
    return '';
  }
  return label.trim().toLowerCase()
  // Remove common required field indicators
  .replace(/\s*\*+\s*$/, '') // "Name *" → "Name"
  .replace(/\s*\(required\)\s*$/i, '') // "Name (Required)" → "Name"
  .replace(/\s*:\s*$/, '') // "Name:" → "Name"
  .trim();
}

/**
 * Normalizes an email address for conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} email The email address to normalize.
 * @return {string} The normalized email address.
 */
function normalizeEmail(email) {
  const normalizedEmail = normalizeValue(email);
  const atIndex = normalizedEmail.lastIndexOf('@');

  // If there is no '@' in the email, return it as is.
  if (atIndex === -1) {
    return normalizedEmail;
  }
  const domain = normalizedEmail.slice(atIndex + 1);

  // Check if it is a 'gmail.com' or 'googlemail.com' address.
  if (['gmail.com', 'googlemail.com'].includes(domain)) {
    const prefix = normalizedEmail.slice(0, atIndex);

    // Remove dots from the prefix.
    const normalizedPrefix = prefix.replace(/\./g, '');
    return "".concat(normalizedPrefix, "@").concat(domain);
  }
  return normalizedEmail;
}

/**
 * Determines if a string has a phone-like pattern.
 *
 * @since 1.162.0
 *
 * @param {string} value The string to validate.
 * @return {boolean} Whether the string passed has a phone-like pattern or not.
 */
function hasPhoneLikePattern(value) {
  const digits = value.replace(/\D/g, '');
  if (digits.length < PHONE_MIN_DIGIT_COUNT || digits.length < value.length / 2) {
    return false;
  }

  // Ensure the string only contains digits and phone-like separators, such as spaces, dashes, parentheses, plus signs, and dots.
  return /^[\s\-()+.\d]*$/.test(value);
}

/**
 * Normalizes a phone number for conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} phone The phone number to normalize.
 * @return {string} The normalized phone number.
 */
function normalizePhone(phone) {
  const normalizedPhone = normalizeValue(phone);

  // Remove all non-numeric characters.
  const digits = normalizedPhone.replace(/\D/g, '');

  // If the phone number starts with a '+' sign, keep it.
  if (normalizedPhone.startsWith('+')) {
    return "+".concat(digits);
  }
  return digits;
}

/**
 * Checks if a value is likely an email address.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to check.
 * @return {boolean} True if the value is likely an email address, false otherwise.
 */
function isLikelyEmail(value) {
  if (!value) {
    return false;
  }
  const normalizedEmail = normalizeEmail(value);
  const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailPattern.test(normalizedEmail);
}

/**
 * Checks if a value is likely a phone number.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to check.
 * @return {boolean} True if the value is likely a phone number, false otherwise.
 */
function isLikelyPhone(value) {
  if (!value) {
    return false;
  }
  if (!hasPhoneLikePattern(value)) {
    return false;
  }
  const normalizedPhone = normalizePhone(value);
  const phonePattern = /^\+?\d{7,}$/;
  if (!phonePattern.test(normalizedPhone)) {
    return false;
  }

  // Reduce false positives: reject plain numeric strings without formatting or international prefix.
  // Allow formatted numbers (e.g., '123-456-7890', '(555) 123-4567') and international format (e.g., '+1234567890').
  const hasFormatting = /[\s\-()+.]/.test(value);
  const hasInternationalPrefix = value.trim().startsWith('+');

  // If it's a plain numeric string (no formatting and no + prefix), reject it to avoid false positives.
  if (!hasFormatting && !hasInternationalPrefix) {
    return false;
  }
  return true;
}

/**
 * Classifies a field as PII based on its metadata.
 *
 * @since 1.161.0
 *
 * @param {Object} fieldMeta The metadata of the field to classify.
 * @return {Object|null} An object containing the PII type and value, or null if not classified.
 */
function classifyPII(fieldMeta) {
  let {
    type,
    name,
    value,
    label
  } = fieldMeta || {};
  type = normalizeValue(type);
  name = normalizeValue(name);
  value = normalizeValue(value);
  label = normalizeLabel(label);

  // First check explicit field types (most reliable).
  switch (type) {
    case 'email':
      return {
        type: PII_TYPE.EMAIL,
        value: normalizeEmail(value)
      };
    case 'tel':
      return {
        type: PII_TYPE.PHONE,
        value: normalizePhone(value)
      };
  }

  // Then check email patterns (emails are more distinctive than phone patterns).
  if (isLikelyEmail(value)) {
    return {
      type: PII_TYPE.EMAIL,
      value: normalizeEmail(value)
    };
  }

  // Then check field name/label indicators for all PII types (context-based detection).
  if (PII_INDICATORS[PII_TYPE.EMAIL].includes(name) || PII_INDICATORS[PII_TYPE.EMAIL].includes(label)) {
    return {
      type: PII_TYPE.EMAIL,
      value: normalizeEmail(value)
    };
  }
  if (PII_INDICATORS[PII_TYPE.PHONE].includes(name) || PII_INDICATORS[PII_TYPE.PHONE].includes(label)) {
    return {
      type: PII_TYPE.PHONE,
      value: normalizePhone(value)
    };
  }
  if (PII_INDICATORS[PII_TYPE.NAME].includes(name) || PII_INDICATORS[PII_TYPE.NAME].includes(label)) {
    return {
      type: PII_TYPE.NAME,
      value: normalizeValue(value)
    };
  }

  // Finally, use pattern matching as fallback (most prone to false positives).
  if (isLikelyPhone(value)) {
    return {
      type: PII_TYPE.PHONE,
      value: normalizePhone(value)
    };
  }
  return null;
}

/**
 * Extracts and formats name fields for Google Tag's user_data address object.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {Object|undefined} An object containing normalized first_name and optionally last_name, or undefined if no names found.
 */
function getAddress(fields) {
  const names = fields.filter(_ref => {
    let {
      type
    } = _ref;
    return type === PII_TYPE.NAME;
  }).map(_ref2 => {
    let {
      value
    } = _ref2;
    return normalizeValue(value);
  }).filter(Boolean);
  if (!names.length) {
    return undefined;
  }
  const [firstName, ...lastNames] = names.length === 1 ? names[0].split(' ') : names;
  return _objectSpread({
    first_name: firstName
  }, (lastNames === null || lastNames === void 0 ? void 0 : lastNames.length) > 0 ? {
    last_name: lastNames.join(' ')
  } : {});
}

/**
 * Extracts the email address from detected PII fields.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {string|undefined} The email address if found, undefined otherwise.
 */
function getEmail(fields) {
  var _fields$find;
  return (_fields$find = fields.find(_ref3 => {
    let {
      type
    } = _ref3;
    return type === PII_TYPE.EMAIL;
  })) === null || _fields$find === void 0 ? void 0 : _fields$find.value;
}

/**
 * Extracts the phone number from detected PII fields.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {string|undefined} The phone number if found, undefined otherwise.
 */
function getPhoneNumber(fields) {
  var _fields$find2;
  return (_fields$find2 = fields.find(_ref4 => {
    let {
      type
    } = _ref4;
    return type === PII_TYPE.PHONE;
  })) === null || _fields$find2 === void 0 ? void 0 : _fields$find2.value;
}

/**
 * Extracts and classifies user data from a WPForms form submission.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {Object|undefined} A user_data object containing detected PII (address, email, phone_number), or undefined if no PII found.
 */
function getUserData(fields) {
  const userDataFields = [['address', getAddress(fields)], ['email', getEmail(fields)], ['phone_number', getPhoneNumber(fields)]].filter(_ref5 => {
    let [, value] = _ref5;
    return value;
  });
  if (userDataFields.length === 0) {
    return undefined;
  }
  return Object.fromEntries(userDataFields);
}
;// ./js/event-providers/optin-monster.js
/**
 * Site Kit by Google, Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Internal dependencies
 */

__webpack_require__.g.document.addEventListener('om.Analytics.track', _ref => {
  let {
    detail
  } = _ref;
  if ('conversion' === detail.Analytics.type) {
    var _global$_googlesiteki, _detail$Campaign, _global$_googlesiteki2, _global$_googlesiteki3;
    const gtagUserDataEnabled = (_global$_googlesiteki = __webpack_require__.g._googlesitekit) === null || _global$_googlesiteki === void 0 ? void 0 : _global$_googlesiteki.gtagUserData;
    const userData = gtagUserDataEnabled && (_detail$Campaign = detail.Campaign) !== null && _detail$Campaign !== void 0 && _detail$Campaign.Form ? getUserDataFromOptinMonsterForm(detail.Campaign.Form) : null;
    const eventData = {
      campaignID: detail.Campaign.id,
      campaignType: detail.Campaign.type
    };
    if (userData) {
      eventData.user_data = userData;
    }
    (_global$_googlesiteki2 = __webpack_require__.g._googlesitekit) === null || _global$_googlesiteki2 === void 0 || (_global$_googlesiteki3 = _global$_googlesiteki2.gtagEvent) === null || _global$_googlesiteki3 === void 0 || _global$_googlesiteki3.call(_global$_googlesiteki2, 'submit_lead_form', eventData);
  }
});

/**
 * Extracts and classifies user data from an OptinMonster form submission.
 *
 * @since 1.164.0
 *
 * @param {Object} form OptinMonster form object.
 * @return {Object|undefined} A user_data object containing detected PII (address, email, phone_number), or undefined if no PII found.
 */
function getUserDataFromOptinMonsterForm(form) {
  if (!form || !form.inputs) {
    return undefined;
  }

  // Extract form fields - OptinMonster stores inputs as array or object of HTML input elements.
  const formFields = Array.isArray(form.inputs) ? form.inputs : Object.values(form.inputs);
  if (!formFields.length) {
    return undefined;
  }

  // Process each HTML input element to classify PII.
  const detectedFields = formFields.map(input => {
    var _document$querySelect;
    // Skip hidden fields to avoid false positives.
    if (input.type === 'hidden') {
      return null;
    }

    // Get label text from associated label element.
    const label = input.id ? (_document$querySelect = document.querySelector("label[for='".concat(input.id, "']"))) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.textContent : input.placeholder || '';
    return classifyPII({
      type: input.type,
      name: input.name,
      value: input.value,
      label
    });
  }).filter(Boolean);

  // Use shared utility function to extract user data.
  return getUserData(detectedFields);
}
/******/ })()
;
//# sourceMappingURL=googlesitekit-events-provider-optin-monster.js.map