MCPcopy
hub / github.com/ampproject/amphtml / setAmpOptInCookie_

Function setAmpOptInCookie_

tools/experiments/experiments.js:281–305  ·  view source on GitHub ↗

* Opts in to / out of the pre-release channels or a specific RTV by setting the * __Host-AMP_OPT_IN cookie. * @param {string} cookieState One of the AMP_OPT_IN_COOKIE enum values, or a * 15-digit RTV.

(cookieState)

Source from the content-addressed store, hash-verified

279 * 15-digit RTV.
280 */
281function setAmpOptInCookie_(cookieState) {
282 let validUntil = 0;
283 if (RTV_PATTERN.test(cookieState)) {
284 validUntil = Date.now() + RTV_COOKIE_MAX_AGE_MS;
285 } else if (cookieState != AMP_OPT_IN_COOKIE.DISABLED) {
286 validUntil = Date.now() + COOKIE_MAX_AGE_MS;
287 }
288 const cookieOptions = {
289 allowOnProxyOrigin: true,
290 // Make sure the cookie is available for the script loads coming from
291 // other domains. Chrome's default of LAX would otherwise prevent it
292 // from being sent.
293 sameSite: SameSite_Enum.NONE,
294 secure: true,
295 };
296 setCookie(
297 window,
298 '__Host-AMP_OPT_IN',
299 cookieState,
300 validUntil,
301 cookieOptions
302 );
303 // Reflect default experiment state.
304 self.location.reload();
305}
306
307/**
308 * Toggles the experiment.

Callers 1

toggleExperiment_Function · 0.85

Calls 4

setCookieFunction · 0.90
nowMethod · 0.80
reloadMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected