* Perform the impression request if it has been provided via * the click param in the viewer arguments. Returns a promise. * @param {!Window} win * @return {!Promise}
(win)
| 171 | * @return {!Promise} |
| 172 | */ |
| 173 | function handleClickUrl(win) { |
| 174 | const ampdoc = Services.ampdoc(win.document.documentElement); |
| 175 | const viewer = Services.viewerForDoc(ampdoc); |
| 176 | |
| 177 | /** @const {?string} */ |
| 178 | const clickUrl = viewer.getParam('click'); |
| 179 | if (!clickUrl) { |
| 180 | return Promise.resolve(); |
| 181 | } |
| 182 | |
| 183 | if (clickUrl.indexOf('https://') != 0) { |
| 184 | user().warn( |
| 185 | 'IMPRESSION', |
| 186 | 'click fragment param should start with https://. Found ', |
| 187 | clickUrl |
| 188 | ); |
| 189 | return Promise.resolve(); |
| 190 | } |
| 191 | |
| 192 | if (WindowInterface.getLocation(win).hash) { |
| 193 | // This is typically done using replaceState inside the viewer. |
| 194 | // If for some reason it failed, get rid of the fragment here to |
| 195 | // avoid duplicate tracking. |
| 196 | WindowInterface.getLocation(win).hash = ''; |
| 197 | } |
| 198 | |
| 199 | // TODO(@zhouyx) need test with a real response. |
| 200 | return ampdoc |
| 201 | .whenFirstVisible() |
| 202 | .then(() => { |
| 203 | return invoke(win, dev().assertString(clickUrl)); |
| 204 | }) |
| 205 | .then((response) => { |
| 206 | applyResponse(win, response); |
| 207 | }) |
| 208 | .catch((err) => { |
| 209 | user().warn('IMPRESSION', 'Error on request clickUrl: ', err); |
| 210 | }); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Send the url to ad server and wait for its response |
no test coverage detected