* parse the response back from ad server * Set for analytics purposes * @param {!Window} win * @param {?JsonObject} response
(win, response)
| 240 | * @param {?JsonObject} response |
| 241 | */ |
| 242 | function 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 |
no test coverage detected