Add filter support for analytics vars
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 the12345.54321part 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
+1 for this. We have a similar formatting tool in our internal analytics library at BuzzFeed.
@avimehta Have you given any further thought to implementing this?
Moving to Backlog since we haven't touched this in awhile.
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
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?
We should also definitely consider function syntax, such as not(...) or base64(...)
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 What about ${toLowerCase(clientId(amp_id))}?
@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?
Having some concerns over additional syntax.
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?
@avimehta has been working on this and could provide updates
This is good! Can we please have a hash function as one of the filters? A publisher has requested this functionality.
Reverted in #6542.
@avimehta Any updates on this?
Closed by https://github.com/ampproject/amphtml/pull/6560.
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 Is this released yet?
Nope.
What's the next step here?
We flip the flag in canary or prod. @lannka?