You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardexpand all lines: extensions/amp-analytics/amp-analytics.md
+18-18
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,11 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
-->
16
16
17
-
**This extension is still a work in progress. Details below can change.**
18
-
19
-
### <aname="amp-analytics"></a>`amp-analytics`
17
+
# <aname="amp-analytics"></a>`amp-analytics`
20
18
21
19
Capture analytics data from an AMP document.
22
20
23
-
####<aname="behavior"></a>Behavior
21
+
## <aname="behavior"></a>Behavior
24
22
25
23
The `<amp-analytics>` element is used to measure activity on an AMP document. The details concerning what is measured and how
26
24
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:
40
38
"account":"ABC123"
41
39
},
42
40
"triggers": {
43
-
"track pageview": {
41
+
"trackPageview": {
44
42
"on":"visible",
45
43
"request":"pageview"
46
44
},
47
-
"track anchor clicks": {
45
+
"trackAnchorClicks": {
48
46
"on":"click",
49
47
"selector":"a",
50
48
"request":"event",
@@ -59,7 +57,7 @@ when the document is first loaded, and each time an `<a>` tag is clicked:
59
57
</amp-analytics>
60
58
```
61
59
62
-
####<aname="attributes"></a>Attributes
60
+
## <aname="attributes"></a>Attributes
63
61
64
62
-`type` This optional attribute can be specified to use one of the built-in analytics providers. Currently supported values for type are:
65
63
-`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:
Configuration may be specified inline (as shown in the example above) or fetched remotely by specifying a URL in the
80
78
`config` attribute. Additionally, built-in configuration for popular analytics vendors can be selected using
81
79
the `type` attribute.
82
80
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
84
82
be merged together such that remote configuration takes precedence over inline configuration, and inline configuration
85
83
takes precendence over vendor configuration.
86
84
@@ -107,7 +105,7 @@ The `<amp-analytics>` configuration object uses the following format:
107
105
}
108
106
}
109
107
```
110
-
######Requests
108
+
### Requests
111
109
The `requests` attribute specifies the URLs used to transmit data to an analytics platform. The `request-name` is used
112
110
in the trigger configuration to specify what request should be sent in response to a pariticular event. The `request-value`
113
111
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
120
118
}
121
119
```
122
120
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.
125
123
126
124
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.
127
125
@@ -132,22 +130,24 @@ The `vars` attribute in the configuration can be used to define new key-value pa
132
130
}
133
131
```
134
132
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.
137
137
138
138
-`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.
140
139
-`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.
141
141
-`vars` An object containing key-value pairs used to override `vars` defined in the top level config, or to specify
142
142
vars unique to this trigger.
143
143
144
144
```javascript
145
145
"triggers": {
146
-
"default pageview": {
146
+
"defaultPageview": {
147
147
"on":"visible",
148
148
"request":"pageview"
149
149
},
150
-
"anchor clicks": {
150
+
"anchorClicks": {
151
151
"on":"click",
152
152
"selector":"a",
153
153
"request":"event",
@@ -158,7 +158,7 @@ The `triggers` attribute describes when an analytics request should be sent.
158
158
}
159
159
```
160
160
161
-
######Transport
161
+
### Transport
162
162
The `transport` attribute specifies how to send a request. The value is an object with fields that
0 commit comments