ads/google/a4a/traffic-experiments.js
/**
 * Check whether Google Ads supports the A4A rendering pathway for a given ad
 * Element on a given Window.  The tests we use are:
 *
 * - The page must have originated in the `cdn.ampproject.org` CDN _or_ we must
 *   be running in local dev mode.
 * - We must be selected in to an A4A traffic experiment and be selected into
 *   the "experiment" branch.
 *
 * If we're selected into the overall traffic experiment, this function will
 * also attach an experiment or control branch ID to the `Element` as
 * a side-effect.
 *
 * @param {!Window} win  Host window for the ad.
 * @param {!Element} element Ad tag Element.
 * @param {string} experimentName Overall name for the experiment.
 * @param {!A4aExperimentBranches} externalBranches experiment and control
 *   branch IDs to use when experiment is triggered externally (e.g., via Google
 *   Search results page).
 * @param {!A4aExperimentBranches} internalBranches experiment and control
 *   branch IDs to use when experiment is triggered internally (i.e., via
 *   client-side selection).
 * @param {!A4aExperimentBranches} delayedExternalBranches
 * @param {!A4aExperimentBranches=} opt_sfgInternalBranches
 * @return {boolean} Whether Google Ads should attempt to render via the A4A
 *   pathway.
 */
Check whether Google Ads supports the A4A rendering pathway for a given ad
Element on a given Window.  The tests we use are.

- The page must have originated in the `cdn.ampproject.org` CDN _or_ we must
be running in local dev mode.
- We must be selected in to an A4A traffic experiment and be selected into
the "experiment" branch.

If we're selected into the overall traffic experiment, this function will
also attach an experiment or control branch ID to the `Element` as
a side-effect.

@param {!Window} win  Host window for the ad.
@param {!Element} element Ad tag Element.
@param {string} experimentName Overall name for the experiment.
@param {!A4aExperimentBranches} externalBranches experiment and control
branch IDs to use when experiment is triggered externally .
@param {!A4aExperimentBranches} internalBranches experiment and control
branch IDs to use when experiment is triggered internally .
@param {!A4aExperimentBranches} delayedExternalBranches
@param {!A4aExperimentBranches=} opt_sfgInternalBranches
@return {boolean} Whether Google Ads should attempt to render via the A4A
pathway.
Check whether Google Ads supports the A4A rendering pathway for a given ad Element on a given Window . The tests we use are . - The page must have originated in the ` cdn . ampproject . org ` CDN _or_ we must be running in local dev mode . - We must be selected in to an A4A traffic experiment and be selected into the " experiment " branch . If we ' re selected into the overall traffic experiment this function will also attach an experiment or control branch ID to the ` Element ` as a side - effect . @param { !Window } win Host window for the ad . @param { !Element } element Ad tag Element . @param { string } experimentName Overall name for the experiment . @param { !A4aExperimentBranches } externalBranches experiment and control branch IDs to use when experiment is triggered externally . @param { !A4aExperimentBranches } internalBranches experiment and control branch IDs to use when experiment is triggered internally . @param { !A4aExperimentBranches } delayedExternalBranches @param { !A4aExperimentBranches = } opt_sfgInternalBranches @return { boolean } Whether Google Ads should attempt to render via the A4A pathway .
function googleAdsIsA4AEnabled(win, element, experimentName,
    externalBranches, internalBranches, delayedExternalBranches,
    opt_sfgInternalBranches) {
  if (!isGoogleAdsA4AValidEnvironment(win)) {
    return false;
  }
  const isSetFromUrl = maybeSetExperimentFromUrl(win, element,
      experimentName, externalBranches.control,
      externalBranches.experiment, delayedExternalBranches.control,
      delayedExternalBranches.experiment,
      opt_sfgInternalBranches ? opt_sfgInternalBranches.control : null,
      opt_sfgInternalBranches ? opt_sfgInternalBranches.experiment : null,
      MANUAL_EXPERIMENT_ID);
  if (!isSetFromUrl) {
    const experimentInfoMap =
         ({});
    const branches = [
      internalBranches.control,
      internalBranches.experiment,
    ];
    experimentInfoMap[experimentName] = {
      isTrafficEligible: () => true,
      branches,
    };
    randomlySelectUnsetExperiments(win, experimentInfoMap);
  }
  if (isExperimentOn(win, experimentName)) {
    const selectedBranch = getExperimentBranch(win, experimentName);
    if (selectedBranch) {
      addExperimentIdToElement(selectedBranch, element);
      const perf = Services.performanceForOrNull(win);
      if (perf) {
        perf.addEnabledExperiment(experimentName + '-' + selectedBranch);
      }
    }
    const selected = selectedBranch == internalBranches.experiment ||
                     selectedBranch == externalBranches.experiment ||
                     selectedBranch == delayedExternalBranches.experiment ||
                     selectedBranch == MANUAL_EXPERIMENT_ID;
    return (selected == !hasLaunched(win, element));
  } else {
    return hasLaunched(win, element);
  }
}
function googleAdsIsA4AEnabled ( win , element , experimentName , externalBranches , internalBranches , delayedExternalBranches , opt_sfgInternalBranches ) { if ( ! isGoogleAdsA4AValidEnvironment ( win ) ) { return false ; } const isSetFromUrl = maybeSetExperimentFromUrl ( win , element , experimentName , externalBranches . control , externalBranches . experiment , delayedExternalBranches . control , delayedExternalBranches . experiment , opt_sfgInternalBranches ? opt_sfgInternalBranches . control : null , opt_sfgInternalBranches ? opt_sfgInternalBranches . experiment : null , MANUAL_EXPERIMENT_ID ) ; if ( ! isSetFromUrl ) { const experimentInfoMap = ( { } ) ; const branches = [ internalBranches . control , internalBranches . experiment , ] ; experimentInfoMap [ experimentName ] = { isTrafficEligible : ( ) => true , branches , } ; randomlySelectUnsetExperiments ( win , experimentInfoMap ) ; } if ( isExperimentOn ( win , experimentName ) ) { const selectedBranch = getExperimentBranch ( win , experimentName ) ; if ( selectedBranch ) { addExperimentIdToElement ( selectedBranch , element ) ; const perf = Services . performanceForOrNull ( win ) ; if ( perf ) { perf . addEnabledExperiment ( experimentName + '-' + selectedBranch ) ; } } const selected = selectedBranch == internalBranches . experiment || selectedBranch == externalBranches . experiment || selectedBranch == delayedExternalBranches . experiment || selectedBranch == MANUAL_EXPERIMENT_ID ; return ( selected == ! hasLaunched ( win , element ) ) ; } else { return hasLaunched ( win , element ) ; } }
Check whether Google Ads supports the A4A rendering pathway for a given ad
 Element on a given Window.
Check whether Google Ads supports the A4A rendering pathway for a given ad Element on a given Window .
// Serving location doesn't qualify for A4A treatment /** @type {!Object<string, !ExperimentInfo>} */ // Note: Because the same experimentName is being used everywhere here, // randomlySelectUnsetExperiments won't add new IDs if // maybeSetExperimentFromUrl has already set something for this // experimentName. // Page is selected into the overall traffic experiment. // In other words, if A4A has not yet launched serve A4A Fast Fetch, // else serve Delayed Fetch. // Detect whether page is on the "experiment" (i.e., use A4A rendering // pathway) branch of the overall traffic experiment or it's on the // "control" (i.e., use traditional, 3p iframe rendering pathway). // Not launched, control branch -> Delayed Fetch // Not launched, experimental branch -> Fast Fetch // Launched, control branch -> Fast Fetch // Launched, experimental branch -> Delayed Fetch (for holdback) // Page is not selected into the overall traffic experiment. // In other words, if A4A has launched serve A4A Fast Fetch, else serve // Delayed Fetch.