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

Function handleClickUrl

src/impression.js:173–211  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

171 * @return {!Promise}
172 */
173function 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

Callers 1

maybeTrackImpressionFunction · 0.85

Calls 12

userFunction · 0.90
devFunction · 0.90
invokeFunction · 0.85
applyResponseFunction · 0.85
resolveMethod · 0.80
warnMethod · 0.80
getLocationMethod · 0.80
catchMethod · 0.80
assertStringMethod · 0.80
getParamMethod · 0.45
thenMethod · 0.45
whenFirstVisibleMethod · 0.45

Tested by

no test coverage detected