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

Function googlePageParameters

ads/google/a4a/utils.js:270–352  ·  view source on GitHub ↗
(a4a, startTime)

Source from the content-addressed store, hash-verified

268 * @return {!Promise<!{[key: string]: null|number|string}>}
269 */
270export function googlePageParameters(a4a, startTime) {
271 const {win} = a4a;
272 const ampDoc = a4a.getAmpDoc();
273 // Do not wait longer than 1 second to retrieve referrer to ensure
274 // viewer integration issues do not cause ad requests to hang indefinitely.
275 const referrerPromise = Services.timerFor(win)
276 .timeoutPromise(1000, Services.viewerForDoc(ampDoc).getReferrerUrl())
277 .catch(() => {
278 dev().expectedError('AMP-A4A', 'Referrer timeout!');
279 return '';
280 });
281 // Collect user agent hints info
282 const uaHintsPromise = Services.timerFor(win)
283 .timeoutPromise(1000, getUserAgentClientHintParameters(win))
284 .catch(() => {
285 dev().expectedError('AMP-A4A', 'UACH timeout!');
286 return {};
287 });
288 // Set dom loading time to first visible if page started in prerender state
289 // determined by truthy value for visibilityState param.
290 const domLoading = a4a.getAmpDoc().getParam('visibilityState')
291 ? a4a.getAmpDoc().getLastVisibleTime()
292 : getNavigationTiming(win, 'domLoading');
293 return Promise.all([
294 getOrCreateAdCid(ampDoc, 'AMP_ECID_GOOGLE', '_ga'),
295 referrerPromise,
296 uaHintsPromise,
297 ]).then((promiseResults) => {
298 const clientId = promiseResults[0];
299 const referrer = promiseResults[1];
300 const uaDataValues = promiseResults[2];
301 const {canonicalUrl, pageViewId} = Services.documentInfoForDoc(ampDoc);
302 // Read by GPT for GA/GPT integration.
303 win.gaGlobal = win.gaGlobal || {cid: clientId, hid: pageViewId};
304 const {screen} = win;
305 const viewport = Services.viewportForDoc(ampDoc);
306 const viewportRect = viewport.getRect();
307 const viewportSize = viewport.getSize();
308 const visibilityState = ampDoc.getVisibilityState();
309 return {
310 'is_amp': a4a.isXhrAllowed()
311 ? AmpAdImplementation.AMP_AD_XHR_TO_IFRAME_OR_AMP
312 : AmpAdImplementation.AMP_AD_IFRAME_GET,
313 'amp_v': mode.version(),
314 'd_imp': '1',
315 'c': getCorrelator(win, ampDoc, clientId),
316 'ga_cid': win.gaGlobal.cid || null,
317 'ga_hid': win.gaGlobal.hid || null,
318 'dt': startTime,
319 'biw': viewportRect.width,
320 'bih': viewportRect.height,
321 'u_aw': screen ? screen.availWidth : null,
322 'u_ah': screen ? screen.availHeight : null,
323 'u_cd': screen ? screen.colorDepth : null,
324 'u_w': screen ? screen.width : null,
325 'u_h': screen ? screen.height : null,
326 'u_tz': -new Date().getTimezoneOffset(),
327 'u_his': getHistoryLength(win),

Callers 2

constructSRARequest_Function · 0.90
googleAdUrlFunction · 0.85

Calls 15

devFunction · 0.90
getOrCreateAdCidFunction · 0.90
catchMethod · 0.80
timeoutPromiseMethod · 0.80
stringifyMethod · 0.80
getNavigationTimingFunction · 0.70
getCorrelatorFunction · 0.70
getHistoryLengthFunction · 0.70
topWindowUrlOrDomainFunction · 0.70

Tested by

no test coverage detected