Skip to content

Commit

Permalink
Add segment
Browse files Browse the repository at this point in the history
  • Loading branch information
yields committed Jun 21, 2016
1 parent 93c60e2 commit 4143811
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
26 changes: 25 additions & 1 deletion examples/analytics.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,31 @@
</amp-analytics>
<!-- End SimpleReach Example -->

<!-- Segment analytics tracking -->
<amp-analytics type="segment">
<script type="application/json">
{
"vars": {
"writeKey": "p74lml96co",
"name": "Page name"
},
"extraUrlParams": {
"properties.author.name": "John"
},
"triggers": {
"click": {
"on": "click",
"selector": "#test1",
"request": "track",
"vars": {
"event": "click"
}
}
}
}
</script>
</amp-analytics>

<!-- Snowplow Analytics tracking -->
<amp-analytics type="snowplow" id="snowplow">
<script type="application/json">
Expand Down Expand Up @@ -651,4 +676,3 @@ <h1 id="top">AMP Analytics</h1>
</amp-anim>
</body>
</html>

6 changes: 6 additions & 0 deletions extensions/amp-analytics/0.1/test/vendor-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
"visible": "https://edge.simplereach.com/n?amp=true&pid=$pid&title=_title_&url=_canonical_url_&date=$published_at&authors=$authors&channels=$categories&tags=$tags&referrer=_document_referrer_&page_url=_source_url_&user_id=_client_id_&domain=_canonical_host_",
"timer": "https://edge.simplereach.com/t?amp=true&pid=$pid&title=_title_&url=_canonical_url_&date=$published_at&authors=$authors&channels=$categories&tags=$tags&referrer=_document_referrer_&page_url=_source_url_&user_id=_client_id_&domain=_canonical_host_&t=5000&e=5000"
},
"segment": {
"host": "https://api.segment.io/v1/pixel",
"base": "?writeKey=$writeKey&anonymousId=$anonymousId&context.locale=_browser_language_&context.page.path=_canonical_path_&context.page.url=_canonical_url_&context.page.referrer=_document_referrer_&context.page.title=_title_&context.screen.width=_screen_width_&context.screen.height=_screen_height_",
"page": "https://api.segment.io/v1/pixel/page?writeKey=$writeKey&anonymousId=$anonymousId&context.locale=_browser_language_&context.page.path=_canonical_path_&context.page.url=_canonical_url_&context.page.referrer=_document_referrer_&context.page.title=_title_&context.screen.width=_screen_width_&context.screen.height=_screen_height_&name=$name",
"track": "https://api.segment.io/v1/pixel/track?writeKey=$writeKey&anonymousId=$anonymousId&context.locale=_browser_language_&context.page.path=_canonical_path_&context.page.url=_canonical_url_&context.page.referrer=_document_referrer_&context.page.title=_title_&context.screen.width=_screen_width_&context.screen.height=_screen_height_&event=$event"
},
"snowplow": {
"aaVersion": "amp-0.1",
"basePrefix": "https://$collectorHost/i?url=_canonical_url_&page=_title_&res=_screen_width_x_screen_height_&stm=_timestamp_&tz=_timezone_&aid=$appId&p=web&tv=amp-0.1",
Expand Down
32 changes: 31 additions & 1 deletion extensions/amp-analytics/0.1/vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,37 @@ export const ANALYTICS_CONFIG = {
},
},

'segment': {
'transport': {
'beacon': false,
'xhrpost': false,
'image': true,
},
'vars': {
'anonymousId': 'CLIENT_ID(segment_amp_id)',
},
'requests': {
'host': 'https://api.segment.io/v1/pixel',
'base': '?writeKey=${writeKey}' +
'&anonymousId=${anonymousId}' +
'&context.locale=${browserLanguage}' +
'&context.page.path=${canonicalPath}' +
'&context.page.url=${canonicalUrl}' +
'&context.page.referrer=${documentReferrer}' +
'&context.page.title=${title}' +
'&context.screen.width=${screenWidth}' +
'&context.screen.height=${screenHeight}',
'page': '${host}/page${base}&name=${name}',
'track': '${host}/track${base}&event=${event}',
},
'triggers': {
'page': {
'on': 'visible',
'request': 'page',
},
},
},

'snowplow': {
'requests': {
'aaVersion': 'amp-0.1',
Expand Down Expand Up @@ -843,4 +874,3 @@ ANALYTICS_CONFIG['adobeanalytics_nativeConfig']

ANALYTICS_CONFIG['oewa']['triggers']['pageview']['iframe' +
/* TEMPORARY EXCEPTION */ 'Ping'] = true;

7 changes: 7 additions & 0 deletions extensions/amp-analytics/amp-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ Type attribute value: `quantcast`

Adds support for Quantcast Measurement. More details for adding Quantcast Measurement can be found at [quantcast.com](https://www.quantcast.com/help/guides/)

## Segment

Type attribute value: `segment`

Adds support for segment page views and events.
To see the full list of fields that you can send, see [Segment Spec](https://segment.com/docs/spec/).

### SOASTA mPulse

Type attribute value: `mpulse`
Expand Down

0 comments on commit 4143811

Please sign in to comment.