extensions/amp-analytics/0.1/iframe-transport.js
/**
   * Create a cross-domain iframe for third-party vendor anaytlics
   * @return {!FrameData}
   * @VisibleForTesting
   */
Create a cross-domain iframe for third-party vendor anaytlics
@return {!FrameData}
@VisibleForTesting
Create a cross - domain iframe for third - party vendor anaytlics @return { !FrameData } @VisibleForTesting
createCrossDomainIframe() {
    const sentinel = IframeTransport.createUniqueId_();
    const useLocal = getMode().localDev || getMode().test;
    const useRtvVersion = !useLocal;
    const scriptSrc = calculateEntryPointScriptUrl(
        this.win_.parent.location, 'iframe-transport-client-lib',
        useLocal, useRtvVersion);
    const frameName = JSON.stringify( ({
      scriptSrc,
      sentinel,
    }));
    const frame = createElementWithAttributes(this.win_.document, 'iframe',
         ({
          sandbox: 'allow-scripts allow-same-origin',
          name: frameName,
          'data-amp-3p-sentinel': sentinel,
        }));
    frame.sentinel = sentinel;
    setStyles(frame, {
      display: 'none',
    });
    frame.src = this.frameUrl_;
    const frameData =  ({
      frame,
      usageCount: 1,
      queue: new IframeTransportMessageQueue(this.win_,
          (frame)),
    });
    IframeTransport.crossDomainIframes_[this.type_] = frameData;
    return frameData;
  }
createCrossDomainIframe ( ) { const sentinel = IframeTransport . createUniqueId_ ( ) ; const useLocal = getMode ( ) . localDev || getMode ( ) . test ; const useRtvVersion = ! useLocal ; const scriptSrc = calculateEntryPointScriptUrl ( this . win_ . parent . location , 'iframe-transport-client-lib' , useLocal , useRtvVersion ) ; const frameName = JSON . stringify ( ( { scriptSrc , sentinel , } ) ) ; const frame = createElementWithAttributes ( this . win_ . document , 'iframe' , ( { sandbox : 'allow-scripts allow-same-origin' , name : frameName , 'data-amp-3p-sentinel' : sentinel , } ) ) ; frame . sentinel = sentinel ; setStyles ( frame , { display : 'none' , } ) ; frame . src = this . frameUrl_ ; const frameData = ( { frame , usageCount : 1 , queue : new IframeTransportMessageQueue ( this . win_ , ( frame ) ) , } ) ; IframeTransport . crossDomainIframes_ [ this . type_ ] = frameData ; return frameData ; }
Create a cross-domain iframe for third-party vendor anaytlics
 @return {!FrameData}
 @VisibleForTesting
Create a cross - domain iframe for third - party vendor anaytlics @return { !FrameData } @VisibleForTesting
// Explanation of IDs: // Each instance of IframeTransport (owned by a specific amp-analytics // tag, in turn owned by a specific creative) has an ID in this._id. // Each cross-domain iframe also has an ID, stored here in sentinel. // These two types of IDs are drawn from the same pool of numbers, and // are thus mutually unique. // There is a many-to-one relationship, in that several creatives may // utilize the same analytics vendor, so perhaps creatives #1 & #2 might // both use xframe #3. // Of course, a given creative may use multiple analytics vendors, but // in that case it would use multiple amp-analytics tags, so the // iframeTransport.id_ -> sentinel relationship is *not* many-to-many. /** @type {JsonObject} */ /** @type {!JsonObject} */ /** @const {FrameData} */ /** @type {!HTMLIFrameElement} */