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

Function getExtraParamsUrl

src/impression.js:296–323  ·  view source on GitHub ↗
(win, target)

Source from the content-addressed store, hash-verified

294 * @return {string}
295 */
296export function getExtraParamsUrl(win, target) {
297 // Get an array with extra params that needs to append.
298 const url = parseUrlDeprecated(WindowInterface.getLocation(win).href);
299 const params = parseQueryString(url.search);
300 const appendParams = [];
301 for (let i = 0; i < DEFAULT_APPEND_URL_PARAM.length; i++) {
302 const param = DEFAULT_APPEND_URL_PARAM[i];
303 if (typeof params[param] !== 'undefined') {
304 appendParams.push(param);
305 }
306 }
307
308 // Check if the param already exists
309 const additionalUrlParams = target.getAttribute('data-amp-addparams');
310 let {href} = target;
311 if (additionalUrlParams) {
312 href = addParamsToUrl(href, parseQueryString(additionalUrlParams));
313 }
314 const loc = parseUrlDeprecated(href);
315 const existParams = parseQueryString(loc.search);
316 for (let i = appendParams.length - 1; i >= 0; i--) {
317 const param = appendParams[i];
318 if (typeof existParams[param] !== 'undefined') {
319 appendParams.splice(i, 1);
320 }
321 }
322 return getQueryParamUrl(appendParams);
323}
324
325/**
326 * Helper method to convert an query param array to string

Callers 2

test-impression.jsFile · 0.90
expandVarsForAnchor_Method · 0.90

Calls 7

parseUrlDeprecatedFunction · 0.90
parseQueryStringFunction · 0.90
addParamsToUrlFunction · 0.90
getQueryParamUrlFunction · 0.85
getLocationMethod · 0.80
getAttributeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected