Skip to content

Commit 1b6c874

Browse files
committed
Updates to documentations and examples based on feedback.
Changes in this commit: - Removed space from trigger name and documented the suggested characters. (Note that the naming is not enforced). - Restructured the document to follow same pattern as ./analytics-vars.md. - Added comments about trigger names.
1 parent 08be18c commit 1b6c874

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

examples/analytics.amp.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"title": "Example Request"
3232
},
3333
"triggers": {
34-
"default pageview": {
34+
"defaultPageview": {
3535
"on": "visible",
3636
"request": "event",
3737
"vars": {
@@ -51,14 +51,14 @@
5151
"account": "UA-YYYY-Y"
5252
},
5353
"triggers": {
54-
"default pageview": {
54+
"defaultPageview": {
5555
"on": "visible",
5656
"request": "pageview",
5757
"vars": {
5858
"title": "Example Pageview"
5959
}
6060
},
61-
"click on #test1 trigger": {
61+
"clickOnTest1Trigger": {
6262
"on": "click",
6363
"selector": "#test1",
6464
"request": "event",
@@ -67,7 +67,7 @@
6767
"eventAction": "clicked-test1"
6868
}
6969
},
70-
"click on #top trigger": {
70+
"clickOnTopTrigger": {
7171
"on": "click",
7272
"selector": "#top",
7373
"request": "event",

examples/analytics.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"title": "Example Request"
77
},
88
"triggers": {
9-
"remote pageview": {
9+
"remotePageview": {
1010
"on": "visible",
1111
"request": "event"
1212
}

extensions/amp-analytics/amp-analytics.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
1616

17-
**This extension is still a work in progress. Details below can change.**
18-
19-
### <a name="amp-analytics"></a>`amp-analytics`
17+
# <a name="amp-analytics"></a>`amp-analytics`
2018

2119
Capture analytics data from an AMP document.
2220

23-
#### <a name="behavior"></a>Behavior
21+
## <a name="behavior"></a>Behavior
2422

2523
The `<amp-analytics>` element is used to measure activity on an AMP document. The details concerning what is measured and how
2624
that data is sent to an analytics server is specified in a JSON configuration object.
@@ -40,11 +38,11 @@ when the document is first loaded, and each time an `<a>` tag is clicked:
4038
"account": "ABC123"
4139
},
4240
"triggers": {
43-
"track pageview": {
41+
"trackPageview": {
4442
"on": "visible",
4543
"request": "pageview"
4644
},
47-
"track anchor clicks": {
45+
"trackAnchorClicks": {
4846
"on": "click",
4947
"selector": "a",
5048
"request": "event",
@@ -59,7 +57,7 @@ when the document is first loaded, and each time an `<a>` tag is clicked:
5957
</amp-analytics>
6058
```
6159

62-
#### <a name="attributes"></a>Attributes
60+
## <a name="attributes"></a>Attributes
6361

6462
- `type` This optional attribute can be specified to use one of the built-in analytics providers. Currently supported values for type are:
6563
- `googleanalytics`: Adds support for Google Analytics. More details for adding Google Analytics support can be found at [developers.google.com](https://developers.google.com/analytics/devguides/collection/amp-analytics/).
@@ -74,13 +72,13 @@ when the document is first loaded, and each time an `<a>` tag is clicked:
7472
<amp-analytics config="https://example.com/analytics.config.json"></amp-analytics>
7573
```
7674
77-
#### Configuration
75+
## Configuration
7876
7977
Configuration may be specified inline (as shown in the example above) or fetched remotely by specifying a URL in the
8078
`config` attribute. Additionally, built-in configuration for popular analytics vendors can be selected using
8179
the `type` attribute.
8280
83-
If configuration data from more than one of these sources is used, the configuration objects will
81+
If configuration data from more than one of these sources is used, the configuration objects(vars, requests and triggers) will
8482
be merged together such that remote configuration takes precedence over inline configuration, and inline configuration
8583
takes precendence over vendor configuration.
8684
@@ -107,7 +105,7 @@ The `<amp-analytics>` configuration object uses the following format:
107105
}
108106
}
109107
```
110-
###### Requests
108+
### Requests
111109
The `requests` attribute specifies the URLs used to transmit data to an analytics platform. The `request-name` is used
112110
in the trigger configuration to specify what request should be sent in response to a pariticular event. The `request-value`
113111
is an https URL. These values may include placeholder tokens that can reference other requests or variables.
@@ -120,8 +118,8 @@ is an https URL. These values may include placeholder tokens that can reference
120118
}
121119
```
122120

123-
###### Vars
124-
`amp-analytics` defines many basic variables that can be used in requests. A list of all such variables is available [here](./analytics-vars.md). In addition, all the variables supported by [AMP HTML URL Variable Substitutions](../../spec/amp-var-substitutions.md) are also supported.
121+
### Vars
122+
`amp-analytics` defines many basic variables that can be used in requests. A list of all such variables is available [here](./analytics-vars.md). In addition, all the variables supported by [AMP HTML URL Variable Substitutions](../../spec/amp-var-substitutions.md) are also supported.
125123

126124
The `vars` attribute in the configuration can be used to define new key-value pairs or override existing variables that can be referenced in `request` values. New variables are commonly used to specify publisher specific information.
127125

@@ -132,22 +130,24 @@ The `vars` attribute in the configuration can be used to define new key-value pa
132130
}
133131
```
134132

135-
###### Triggers
136-
The `triggers` attribute describes when an analytics request should be sent.
133+
### Triggers
134+
The `triggers` attribute describes when an analytics request should be sent. It contains a key-value pair of trigger-name and
135+
trigger-configuration. Trigger name can be any string comprised of alphanumeric characters (a-zA-Z0-9). Triggers from a
136+
configuration with lower precedence are overridden by triggers with the same names from a configuration with higher precedence.
137137

138138
- `on` (required) The event to listener for. Valid values are `visible` and `click`.
139-
- `selector` A CSS selector used to refine which elements should be tracked. Use value `*` to track all elements.
140139
- `request` (required) Name of the request to send (as specified in the `requests` section).
140+
- `selector` A CSS selector used to refine which elements should be tracked. Use value `*` to track all elements.
141141
- `vars` An object containing key-value pairs used to override `vars` defined in the top level config, or to specify
142142
vars unique to this trigger.
143143

144144
```javascript
145145
"triggers": {
146-
"default pageview": {
146+
"defaultPageview": {
147147
"on": "visible",
148148
"request": "pageview"
149149
},
150-
"anchor clicks": {
150+
"anchorClicks": {
151151
"on": "click",
152152
"selector": "a",
153153
"request": "event",
@@ -158,7 +158,7 @@ The `triggers` attribute describes when an analytics request should be sent.
158158
}
159159
```
160160

161-
###### Transport
161+
### Transport
162162
The `transport` attribute specifies how to send a request. The value is an object with fields that
163163
indicate which transport methods are acceptable.
164164

0 commit comments

Comments
 (0)