Skip to content

Commit

Permalink
馃摉 Documentation for requestOrigin (ampproject#23138)
Browse files Browse the repository at this point in the history
* Add docs for requestOrigin

* update with comments
  • Loading branch information
jonathantyng-amp authored and zhouyx committed Jul 1, 2019
1 parent b5d4b5e commit 5a5fef1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions extensions/amp-analytics/amp-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ The `requests` configuration object specifies the URLs used to transmit data to
The properties for defining a request with an object are:
- `baseUrl`: Defines the url of the request (required).
- `reportWindow`: An optional property to specify the time (in seconds) to stop reporting requests. The trigger with `important: true` overrides the maximum report window constraint.
- [`origin`](#request-origin): An optional property to specify the origin for requests
In this example, all requests are valid.
Expand All @@ -291,6 +292,42 @@ In this example, all requests are valid.
Some analytics providers have an already-provided configuration, which you use via the `type` attribute. If you are using an analytics provider, you may not need to include requests information. See your vendor documentation to find out if requests need to be configured, and how.
##### Request Origin
The top-level `requestOrigin` property accepts an absolute URL and defines the origin for requests. If `requestOrigin` is declared, the origin will be extracted from the value and it will be prepended to `baseUrl`. `requestOrigin` accepts and supports variables substitution. Variables will **not** be encoded in `requestOrigin`.
```javascript
"requestOrigin": "${example}/ignore_query",
"requests": {
"base": "/analytics?a=${account}",
"pageview": {
"baseUrl": "${base}&type=pageview"
},
"event": {
"baseUrl": "${base}&type=event",
}
},
"vars": {
"example": "https://example.com"
}
```
In this example, outgoing requests will be `https://example.com/analytics?a=${account}&type=pageview` for `pageview` requests and `https://example.com/analytics?a=${account}&type=event` for `event` requests. Notice that the `requestOrigin` value is not encoded and that only the origin is added to `baseUrl`.

Request objects can also have an `origin` property that will override this top-level `requestOrigin` property.

```javascript
"requestOrigin": "https://example.com",
"requests": {
"pageview": {
"origin": 'https://newexample.com',
"baseUrl": "/analytics?type=pageview"
},
}
```

In this example, the outgoing request will be `https://newexample.com/analytics?type=pageview` for the `pageview` request.


##### Batching configs
To reduce the number of request pings, you can specify batching behaviors in the request configuration. Any [`extraUrlParams`](#extra-url-params) from `triggers` that use the same request are appended to the `baseUrl` of the request.

Expand Down

0 comments on commit 5a5fef1

Please sign in to comment.