Skip to content

Commit

Permalink
✨ Ssp params extended (ampproject#35957)
Browse files Browse the repository at this point in the history
Co-authored-by: PetrBlaha <petr.blaha@firma.seznam.cz>
  • Loading branch information
2 people authored and Mahir committed Sep 9, 2021
1 parent eb6d869 commit 2a3a995
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ads/vendors/ssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function forceElementReflow(element) {
*/
export function ssp(global, data) {
// validate AMP input data- attributes
validateData(data, ['position'], ['site']);
validateData(data, ['position'], ['site', 'said']);

let position = {id: -1};

Expand Down Expand Up @@ -169,6 +169,7 @@ export function ssp(global, data) {

sssp.config({
site: data.site || global.context.canonicalUrl,
said: data.said || null,
});

// propagate relevant data across all ad units
Expand Down
9 changes: 8 additions & 1 deletion ads/vendors/ssp.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
width="480"
height="300"
type="ssp"
data-said="abcd1234"
data-position='{ "id": "id-2", "width": "480", "height": "300", "zoneId": "1234" }'
>
</amp-ad>
Expand All @@ -42,13 +43,19 @@ Required parameters:
| height | Height of AMP Ad (grey fixed border) | `200` |
| type | Type of amp-ad | `ssp` |
| data-position | JSON stringified position object | `{ "id": "id-1", "width": "480", "height": "300", "zoneId": "1234" }` |
| data-said | SAID identificator | `abcd1234` |

### `data-position`

- Object must have required keys `id`, `width`, `height`, `zoneId` (Watch out for uppercase "I" in "id").
- Every position MUST have unique `id`, if you duplicate some id, Ad may be used from another position.
- Attributes `width` and `height` are from AMP specification, and they will set fixed border around Ad.
- Attributes `data-width` and `data-height` are used to fetch SSP Ads on the server (They can different).
- Attributes `data-width` and `data-height` are used to fetch SSP Ads on the server (They can be different).

### `data-said`

- Optional
- String representing `said` identificator

## Contact

Expand Down
18 changes: 15 additions & 3 deletions test/unit/ads/test-ssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describes.fakeWin('amp-ad-ssp', {}, (env) => {
commonData = {
width: '200',
height: '200',
said: 'said1234',
position:
'{ "id": "id-1", "width": "200", "height": "200", "zoneId": "1234" }',
};
Expand Down Expand Up @@ -74,11 +75,12 @@ describes.fakeWin('amp-ad-ssp', {}, (env) => {
{
width: '200',
height: '200',
said: 'said1234',
position:
'{ "id": "id-1", "width": "200", "height": "200", "zoneId": "1234" }',
},
['position'],
['site']
['site', 'said']
);
});

Expand Down Expand Up @@ -156,7 +158,10 @@ describes.fakeWin('amp-ad-ssp', {}, (env) => {
ssp(win, commonData);

expect(sssp.config).to.have.been.calledOnce;
expect(sssp.config).to.have.been.calledWith({site: 'https://test.com'});
expect(sssp.config).to.have.been.calledWith({
site: 'https://test.com',
said: 'said1234',
});
});

it('should call context.noContentAvailable() when position is invalid', () => {
Expand Down Expand Up @@ -238,7 +243,14 @@ describes.fakeWin('amp-ad-ssp', {}, (env) => {

expect(sssp.getAds).to.have.been.calledOnce;
expect(sssp.getAds).to.have.been.calledWith(
[{id: 'id-1', width: '200', height: '200', zoneId: '1234'}],
[
{
id: 'id-1',
width: '200',
height: '200',
zoneId: '1234',
},
],
{AMPcallback: sandbox.match.func}
);
});
Expand Down

0 comments on commit 2a3a995

Please sign in to comment.