Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amp-analytics Segment.com #1292

Closed
kzap opened this issue Jan 5, 2016 · 8 comments
Closed

amp-analytics Segment.com #1292

kzap opened this issue Jan 5, 2016 · 8 comments

Comments

@kzap
Copy link

kzap commented Jan 5, 2016

I'm really keen to implement Segment.com's API for AMP-Analytics but am running into road blocks.
It'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?

https://segment.com/docs/libraries/pixel/
https://segment.com/docs/libraries/http/

My 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.

Some implementation of where #1162 was going would be appreciated but the main issues I see are

1.) 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

Example:

"requests": {
    "host": "https://api.segment.io/v1/pixel",
    "basePrefix": "writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}",
    "pageData": "${basePrefix}&url=${ampdocUrl}&name=${title}",
    "page": "${host}/page/?data=${btoa(${pageData})}"
},

2.) Support for Post Body Data. sendBeacon and XHR can do this, but whats more important is how the data is specified.
Suggestion:

"requests": {
    "host": "https://api.segment.io/v1/pixel",
    "basePrefix": "writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}",
    "page": {
        host: "${host}"
        path: "/page/?${basePrefix}"
        data: {
            url: "${ampdocUrl}",
            name: "${title}"
        }
    },
    "event": {
        host: "${host}"
        path: "/track/?${basePrefix}"
        data: "stringExample=1&orFormEncoded=2"
    }
},

3.) 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

"requests": {
    "host": "https://api.segment.io/v1",
    "basePrefix": "writeKey=${writeKey}&anonymousId=${clientId(ajs_anonymous_id)}",
    "page": {
        host: "${host}"
        path: "/page/?${basePrefix}"
        data: {
            url: "${ampdocUrl}",
            name: "${title}"
        },
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
        }
    }
},
@kzap
Copy link
Author

kzap commented Jan 5, 2016

Reference for MixPanel HTTP API that requires base64 encoded string:
https://mixpanel.com/help/reference/http

KissMetrics API is much simpler and can use GET and parameters
http://support.kissmetrics.com/apis/specifications

@cramforce
Copy link
Member

Segment seems like a very cool product and very in line with AMP's philosophy!

  • Sending data as post body makes sense, of course.
  • 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.
  • 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.

@kzap
Copy link
Author

kzap commented Jan 28, 2016

ive discussed with the Segment folks and they dont have any way plans to remove base64 or support dot notation in their GET API.

So @cramforce ... if i added this to AMP via a PR would it be considered?

@cramforce
Copy link
Member

Definite yes on base64. I don't completely follow what the dot notation is.

@iefserge
Copy link
Contributor

We're using keen.io for analytics and we have a very similar issue. Keen.io API requires JSON and base64 encoded query parameter (or POST-body) https://keen.io/docs/api/#record-a-single-event.

{
  "requests": {
    ...
    "page": "$(host)/3.0/projects/<id>/events/collection?data=base64(json(${data}))"
  },
  "vars": {
    "data": {
      "key": "value"
    }
  }
}

@kzap
Copy link
Author

kzap commented Jan 29, 2016

Nvm the dot notation but ok ill work on something for base64 and post

Andre
On Jan 30, 2016 6:54 AM, "Serge" notifications@github.com wrote:

We're using keen.io for analytics and we have a very similar issue.
Keen.io API requires JSON and base64 encoded query parameter (or POST-body)
https://keen.io/docs/api/#record-a-single-event.

{
"requests": {
...
"page": "$(host)/3.0/projects//events/collection?data=base64(json(${data}))"
},
"vars": {
"data": {
"key": "value"
}
}
}


Reply to this email directly or view it on GitHub
#1292 (comment)
.

@rudygalfi rudygalfi added this to the M2 milestone Feb 4, 2016
@rudygalfi
Copy link
Contributor

FYI: I spun off the request for supporting POST for JSON to #1798.

@rudygalfi rudygalfi modified the milestones: M2, Backlog Mar 4, 2016
@kzap
Copy link
Author

kzap commented Jul 4, 2016

#3630 implements this already :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants