Skip to content

Commit

Permalink
add test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyx committed Jan 25, 2018
1 parent 879e8c3 commit e3ddbd5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions extensions/amp-analytics/0.1/test/test-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ describes.realWin('Requests', {amp: 1}, env => {
expect(h2Spy).to.be.calledOnce;
});

it('should respect trigger immediate', function* () {
const spy = sandbox.spy();
const r = {'baseUrl': 'r', 'maxDelay': 1};
const handler = new RequestHandler(ampdoc, r, preconnect, spy, false);
const expansionOptions = new ExpansionOptions({});
handler.send({'e': '1'}, {}, expansionOptions);
clock.tick(100);
handler.send({'e': '2'}, {'immediate': 'str'}, expansionOptions);
clock.tick(100);
handler.send({'e': '3'}, {'immediate': true}, expansionOptions);
yield macroTask();
expect(spy).to.be.calledOnce;
expect(spy.args[0][0]).to.equal('r?e=1&e=2&e=3');
spy.reset();
handler.send({'e': '4'}, {}, expansionOptions);
clock.tick(800);
yield macroTask();
expect(spy).to.not.be.called;
clock.tick(200);
yield macroTask();
expect(spy).to.be.calledOnce;
expect(spy.args[0][0]).to.equal('r?e=4');
});

it('should batch multiple send', function* () {
const spy = sandbox.spy();
const r = {'baseUrl': 'r2', 'maxDelay': 1};
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-analytics/amp-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ The `triggers` configuration object describes when an analytics request should b
- `on` (required) The event to listen for. Valid values are `render-start`, `ini-load`, `click`, `scroll`, `timer`, `visible`, `hidden`, `user-error`, [`access-*`](../amp-access/amp-access-analytics.md), and [`video-*`](./amp-video-analytics.md)
- `request` (required) Name of the request to send (as specified in the `requests` section).
- `vars` An object containing key-value pairs used to override `vars` defined in the top level config, or to specify vars unique to this trigger.
- `immediate` can be specified to work with request that support batching behavior. Setting `immediate` to `true` can help to flush batched request queue with some certain trigger. In this case, it's possible to reduce the request pings number without losing important trigger events.
- `selector` and `selectionMethod` can be specified for some triggers, such as `click` and `visible`. See [Element selector](#element-selector) for details.
- `scrollSpec` (required when `on` is set to `scroll`) This configuration is used in conjunction with the `scroll` trigger. Please see below for details.
- `timerSpec` (required when `on` is set to `timer`) This configuration is used in conjunction with the `timer` trigger. Please see below for details.
Expand Down

0 comments on commit e3ddbd5

Please sign in to comment.