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

Function applyResponse

src/impression.js:242–274  ·  view source on GitHub ↗

* parse the response back from ad server * Set for analytics purposes * @param {!Window} win * @param {?JsonObject} response

(win, response)

Source from the content-addressed store, hash-verified

240 * @param {?JsonObject} response
241 */
242function applyResponse(win, response) {
243 if (!response) {
244 return;
245 }
246
247 const adLocation = response['location'];
248 const adTracking = response['tracking_url'];
249
250 // If there is a tracking_url, need to track it
251 // Otherwise track the location
252 const trackUrl = adTracking || adLocation;
253
254 if (trackUrl && !isProxyOrigin(trackUrl)) {
255 // To request the provided trackUrl for tracking purposes.
256 new Image().src = trackUrl;
257 }
258
259 // Replace the location href params with new location params we get (if any).
260 if (adLocation) {
261 if (!win.history.replaceState) {
262 return;
263 }
264
265 const viewer = Services.viewerForDoc(win.document.documentElement);
266 const currentHref = WindowInterface.getLocation(win).href;
267 const url = parseUrlDeprecated(adLocation);
268 const params = parseQueryString(url.search);
269 const newHref = addParamsToUrl(currentHref, params);
270 // TODO: Avoid overwriting the fragment parameter.
271 win.history.replaceState(null, '', newHref);
272 viewer.maybeUpdateFragmentForCct();
273 }
274}
275
276/**
277 * Return a promise that whether appending extra url params to outgoing link is

Callers 1

handleClickUrlFunction · 0.85

Calls 7

isProxyOriginFunction · 0.90
parseUrlDeprecatedFunction · 0.90
parseQueryStringFunction · 0.90
addParamsToUrlFunction · 0.90
getLocationMethod · 0.80
replaceStateMethod · 0.80

Tested by

no test coverage detected