amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Add filter support for analytics vars

Open cramforce opened this issue 10 years ago • 39 comments

Updated by @lannka on 4/3/2017:

Use cases:

  • Adobe Analytics does not like - (dashes) in client ids, which could be enforced with such a mechanism.
  • Google Analytics has cookie value in format of GA1.1.12345.54321, and we want to extract the 12345.54321 part to report as Client ID.

V1

  • Introduce a regex filter, which would address most requirements.

V2

  • Introduce other filters, such as
 Not (negation)
 Trim
 JSON.stringify
 Base64
 Default()
 ToLowerCase
 ToUpperCase

Task break down:

  • [ ] Finalize the design of filter syntax.
  • [ ] Implement rule parser
  • [ ] Implement filter

cramforce avatar Feb 22 '16 17:02 cramforce

+1 for this. We have a similar formatting tool in our internal analytics library at BuzzFeed.

ryanlombardo avatar Mar 18 '16 03:03 ryanlombardo

@avimehta Have you given any further thought to implementing this?

Moving to Backlog since we haven't touched this in awhile.

rudygalfi avatar Aug 25 '16 21:08 rudygalfi

Here are a few things that I could think of implementing. Feel free to add more to the list. wdyt?

  • [ ] Not (negation)
  • [ ] Trim
  • [ ] JSON.stringify
  • [ ] Base64
  • [ ] Default()
  • [ ] ToLowerCase
  • [ ] ToUpperCase

avimehta avatar Aug 25 '16 22:08 avimehta

Looks like a good list.

From a format point of view, we should review the pipe (|) syntax and make sure we definitely want to go that way. How would nesting work?

Doe any of the items on the list address @cramforce's original suggestion of stripping dashes?

rudygalfi avatar Aug 25 '16 23:08 rudygalfi

We should also definitely consider function syntax, such as not(...) or base64(...)

dvoytenko avatar Aug 26 '16 10:08 dvoytenko

none of the items so far listed take care of stripping dashes. The filters should be cheap and simple functions though and can be implemented for such needs.

For Dima's comment, I agree about the function syntax. So a variable could be something like:

${clientId(amp_id)|toLowerCase()|default(emptyCid)}

${jsonVariable|json()|base64()}

We could also make () optional when there are no parameters. That way the syntax gets a little easier:

${clientId(amp_id)|toLowerCase|default(emptyCid)}

${jsonVariable|json|base64}

As for the | syntax, I have not looked into exact details and don't know what could go wrong. An alternative would be to consider nested functions like ${base64(json(jsonVariable))} . Not sure if I like it though.

avimehta avatar Aug 26 '16 18:08 avimehta

@avimehta What about ${toLowerCase(clientId(amp_id))}?

dvoytenko avatar Aug 29 '16 17:08 dvoytenko

@dvoytenko Is this the same as the nested functions that I talk about in the last paragraph? I like the readability of this. It has slightly more involved parsing though. Do you like this more over the other options?

avimehta avatar Aug 29 '16 17:08 avimehta

Having some concerns over additional syntax.

dvoytenko avatar Aug 29 '16 17:08 dvoytenko

I originally raised https://github.com/ampproject/amphtml/issues/2476, and I'm wondering what the latest is on this? I'd like to send a boolean value in my analytics submission based on an access decision made in the client (e.g. barrier: 'NOT AUTHDATA(access)', as described in the other ticket). How close are we to being able to do this?

georgecrawford avatar Oct 10 '16 12:10 georgecrawford

@avimehta has been working on this and could provide updates

rudygalfi avatar Oct 12 '16 03:10 rudygalfi

This is good! Can we please have a hash function as one of the filters? A publisher has requested this functionality.

taymonbeal avatar Oct 12 '16 21:10 taymonbeal

Reverted in #6542.

jridgewell avatar Dec 08 '16 19:12 jridgewell

@avimehta Any updates on this?

rudygalfi avatar Jan 23 '17 17:01 rudygalfi

Closed by https://github.com/ampproject/amphtml/pull/6560.

jridgewell avatar Jan 23 '17 18:01 jridgewell

sorry. Reopening. The feature is behind a flag and needs to be turned on. I think this should be ready in next two weeks.

avimehta avatar Jan 23 '17 22:01 avimehta

@avimehta Is this released yet?

rudygalfi avatar Feb 10 '17 04:02 rudygalfi

Nope.

jridgewell avatar Feb 11 '17 03:02 jridgewell

What's the next step here?

rudygalfi avatar Feb 23 '17 20:02 rudygalfi

We flip the flag in canary or prod. @lannka?

jridgewell avatar Feb 23 '17 21:02 jridgewell