{"action":"created","issue":{"url":"https://api.github.com/repos/ampproject/amphtml/issues/1292","labels_url":"https://api.github.com/repos/ampproject/amphtml/issues/1292/labels{/name}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/1292/comments","events_url":"https://api.github.com/repos/ampproject/amphtml/issues/1292/events","html_url":"https://github.com/ampproject/amphtml/issues/1292","id":124930906,"number":1292,"title":"amp-analytics Segment.com","user":{"login":"kzap","id":62213,"avatar_url":"https://avatars.githubusercontent.com/u/62213?v=3","gravatar_id":"","url":"https://api.github.com/users/kzap","html_url":"https://github.com/kzap","followers_url":"https://api.github.com/users/kzap/followers","following_url":"https://api.github.com/users/kzap/following{/other_user}","gists_url":"https://api.github.com/users/kzap/gists{/gist_id}","starred_url":"https://api.github.com/users/kzap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzap/subscriptions","organizations_url":"https://api.github.com/users/kzap/orgs","repos_url":"https://api.github.com/users/kzap/repos","events_url":"https://api.github.com/users/kzap/events{/privacy}","received_events_url":"https://api.github.com/users/kzap/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-05T09:50:23Z","updated_at":"2016-01-05T15:41:45Z","closed_at":null,"body":"I'm really keen to implement Segment.com's API for AMP-Analytics but am running into road blocks.\r\nIt's nice that we can support POST with sendBeacon or XHR but what would the point of POST be if you cant post data and just a URL?\r\n\r\nhttps://segment.com/docs/libraries/pixel/\r\nhttps://segment.com/docs/libraries/http/\r\n\r\nMy use-case for Segment is that I wouldnt have to write configs for other analytics tools and just rely on Segment's servers to send the data to the other linked analytics services. Very very very useful.\r\n\r\nSome implementation of where #1162 was going would be appreciated but the main issues I see are\r\n\r\n1.) Helpers to transform data. Like how clientId is used now, if we could run any or certain functions to transform data before sending it but specified in the configuration\r\n\r\nExample:\r\n```\r\n\"requests\": {\r\n    \"host\": \"https://api.segment.io/v1/pixel\",\r\n    \"basePrefix\": \"writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}\",\r\n    \"pageData\": \"${basePrefix}&url=${ampdocUrl}&name=${title}\",\r\n    \"page\": \"${host}/page/?data=${btoa(${pageData})}\"\r\n},\r\n```\r\n\r\n2.) Support for Post Body Data. sendBeacon and XHR can do this, but whats more important is how the data is specified. \r\nSuggestion:\r\n```\r\n\"requests\": {\r\n    \"host\": \"https://api.segment.io/v1/pixel\",\r\n    \"basePrefix\": \"writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}\",\r\n    \"page\": {\r\n        host: \"${host}\"\r\n        path: \"/page/?${basePrefix}\"\r\n        data: {\r\n            url: \"${ampdocUrl}\",\r\n            name: \"${title}\"\r\n        }\r\n    },\r\n    \"event\": {\r\n        host: \"${host}\"\r\n        path: \"/track/?${basePrefix}\"\r\n        data: \"stringExample=1&orFormEncoded=2\"\r\n    }\r\n},\r\n```\r\n\r\n3.) Expand it further by allowing custom headers as Segment and maybe others require basic auth headers. Only XHR could do this but still why not case for it, there are use-cases\r\n```\r\n\"requests\": {\r\n    \"host\": \"https://api.segment.io/v1\",\r\n    \"basePrefix\": \"writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}\",\r\n    \"page\": {\r\n        host: \"${host}\"\r\n        path: \"/page/?${basePrefix}\"\r\n        data: {\r\n            url: \"${ampdocUrl}\",\r\n            name: \"${title}\"\r\n        },\r\n        headers: {\r\n            \"Content-Type\": \"application/json\",\r\n            \"Authorization\": \"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\"\r\n        }\r\n    }\r\n},\r\n```"},"comment":{"url":"https://api.github.com/repos/ampproject/amphtml/issues/comments/169038235","html_url":"https://github.com/ampproject/amphtml/issues/1292#issuecomment-169038235","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/1292","id":169038235,"user":{"login":"cramforce","id":89679,"avatar_url":"https://avatars.githubusercontent.com/u/89679?v=3","gravatar_id":"","url":"https://api.github.com/users/cramforce","html_url":"https://github.com/cramforce","followers_url":"https://api.github.com/users/cramforce/followers","following_url":"https://api.github.com/users/cramforce/following{/other_user}","gists_url":"https://api.github.com/users/cramforce/gists{/gist_id}","starred_url":"https://api.github.com/users/cramforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramforce/subscriptions","organizations_url":"https://api.github.com/users/cramforce/orgs","repos_url":"https://api.github.com/users/cramforce/repos","events_url":"https://api.github.com/users/cramforce/events{/privacy}","received_events_url":"https://api.github.com/users/cramforce/received_events","type":"User","site_admin":false},"created_at":"2016-01-05T15:41:45Z","updated_at":"2016-01-05T15:41:45Z","body":"Segment seems like a very cool product and very in line with AMP's philosophy!\r\n\r\n- Sending data as post body makes sense, of course.\r\n- We definitely want the per vendor configuration to be declarative, so there cannot be functions that process data on the client defined in the configuration.\r\n- It is definitely a non-goal to support arbitrary advanced API endpoints. There has to be some kind of middle ground between what can be easily supported using a declarative configuration, a simple, generic client library, and which is likely appropriate for a broad range of backends. That means, posting JSON i probably a good idea, but Segment may need to change their API to be simpler to use from an AMP-like client."}}