(win)
| 56 | * @param {!Window} win |
| 57 | */ |
| 58 | export function maybeTrackImpression(win) { |
| 59 | const deferred = new Deferred(); |
| 60 | const {promise, resolve: resolveImpression} = deferred; |
| 61 | |
| 62 | trackImpressionPromise = Services.timerFor(win) |
| 63 | .timeoutPromise(TIMEOUT_VALUE, promise, 'TrackImpressionPromise timeout') |
| 64 | .catch((error) => { |
| 65 | dev().warn('IMPRESSION', error); |
| 66 | }); |
| 67 | |
| 68 | const viewer = Services.viewerForDoc(win.document.documentElement); |
| 69 | const isTrustedViewerPromise = viewer.isTrustedViewer(); |
| 70 | const isTrustedReferrerPromise = viewer |
| 71 | .getReferrerUrl() |
| 72 | .then((referrer) => isTrustedReferrer(referrer)); |
| 73 | Promise.all([isTrustedViewerPromise, isTrustedReferrerPromise]).then( |
| 74 | (results) => { |
| 75 | const isTrustedViewer = results[0]; |
| 76 | const isTrustedReferrer = results[1]; |
| 77 | // Enable the feature in the case of trusted viewer, |
| 78 | // or trusted referrer |
| 79 | // or with experiment turned on |
| 80 | if ( |
| 81 | !isTrustedViewer && |
| 82 | !isTrustedReferrer && |
| 83 | !isExperimentOn(win, 'alp') |
| 84 | ) { |
| 85 | resolveImpression(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | const replaceUrlPromise = handleReplaceUrl(win); |
| 90 | const clickUrlPromise = handleClickUrl(win); |
| 91 | |
| 92 | Promise.all([replaceUrlPromise, clickUrlPromise]).then( |
| 93 | () => { |
| 94 | resolveImpression(); |
| 95 | }, |
| 96 | () => {} |
| 97 | ); |
| 98 | } |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Signal that impression tracking is not relevant in this environment. |
no test coverage detected