diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js index c291bc302d7f..5375bcda6c98 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js @@ -1224,27 +1224,28 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { if (!this.win.opener || !/\?.*dfpdeb/.test(this.win.location.href)) { return; } + const slotId = this.element.getAttribute('data-slot'); const payload = dict({ 'gutData': JSON.stringify(dict({ 'events': [{ 'timestamp': new Date().getTime(), - 'slotid': this.element.getAttribute('data-slot'), + 'slotid': slotId, 'messageId': 4, }], 'slots': [{ 'contentUrl': this.getCachedAdUrl() || '', - 'id': this.element.getAttribute('data-slot'), - 'leafAdUnitName': this.element.getAttribute('data-slot'), - 'domId': '', - 'lineItemId': this.lineitemId_ || '102158080', - 'creativeId': this.creativeId_ || '88085470120', + 'id': slotId, + 'leafAdUnitName': slotId, + 'domId': 'gpt_unit_' + slotId + '_' + + this.element.getAttribute('data-amp-slot-index'), + 'lineItemId': this.lineitemId_, + 'creativeId': this.creativeId_, }], })), 'userAgent': navigator.userAgent, 'referrer': this.win.location.href, 'messageType': 'LOAD', }); - console.log(payload); this.win.opener.postMessage(payload, '*'); } } diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js index d2f0c3a19043..dd5e69ff6de1 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js @@ -1064,6 +1064,56 @@ describes.realWin('amp-ad-network-doubleclick-impl', realWinConfig, env => { ['https://partner.googleadservices.com', SAFEFRAME_ORIGIN]); }); }); + + describe('Troubleshoot', () => { + beforeEach(() => { + element = doc.createElement('amp-ad'); + element.setAttribute('type', 'doubleclick'); + element.setAttribute('data-slot', 'slotId'); + element.setAttribute('data-amp-slot-index', '0'); + doc.body.appendChild(element); + impl = new AmpAdNetworkDoubleclickImpl(element); + impl.lineitemId_ = '123'; + impl.creativeId_ = '456'; + }); + + afterEach(() => { + doc.body.removeChild(element); + }); + + it('should emit post message', () => { + const slotId = 'slotId' + env.win = { + location: { + href: 'http://localhost:8000/foo?dfpdeb', + }, + opener: { + postMessage: payload => { + expect(payload).to.be.ok; + expect(payload.userAgent).to.be.ok; + expect(payload.referrer).to.be.ok; + expect(payload.messageType).to.equal('LOAD'); + + const gutData = JSON.parse(payload.gutData); + expect(gutData).to.be.ok; + expect(gutData.events[0].timestamp).to.be.ok; + expect(gutData.events[0].slotid).to.equal(slotId); + expect(gutData.events[0].messageId).to.equal(4); + + expect(gutData.slots[0].contentUrl).to.equal(''); + expect(gutData.slots[0].id).to.equal(slotId); + expect(gutData.slots[0].leafAdUnitName).to.equal(slotId); + expect(gutData.slots[0].domId).to.equal( + 'gpt_unit_' + slotId + '_0'); + expect(gutData.slots[0].lineItemId).to.equal('123'); + expect(gutData.slots[0].creativeId).to.equal('456'); + }, + }, + }; + impl.win = env.win; + impl.postTroubleshootMessage_(); + }); + }); });