amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Pass page view id and a client identifier to ads, analytics, etc.

Open cramforce opened this issue 11 years ago • 13 comments

We need a general variable available to amp-pixel, analytics, ads, that is "unique" (Just Math.random should be fine) per page view. So, just a random number we create once per page.

This is a change in https://github.com/ampproject/amphtml/blob/master/src/url-replacements.js

Some ads require access to a CID. Create configuration per ad network for the fallbackCookieName. Will need to figure out how to get consent in this case.

CC @rudygalfi @kashyapnitin @avimehta

cramforce avatar Nov 19 '15 17:11 cramforce

Is this intended to function only as a cachebuster? Math.random() isn't nearly high enough entropy, in our experience, to function as unique pageview ID (across hundreds of billions of pageviews)

joshschwartz avatar Nov 19 '15 20:11 joshschwartz

how about .? Would that make uniqueness a little easier to achieve?

avimehta avatar Nov 19 '15 20:11 avimehta

Unique is a bit of a complicated concept :)

Anyway, good feedback.

How much entropy do you need? Are 64bit enough or do you need 128bit?

cramforce avatar Nov 19 '15 20:11 cramforce

64bit should be enough for ultra-likely-unique-per-week :)

cramforce avatar Nov 19 '15 21:11 cramforce

Actually, shouldn't Math.random be completely sufficient? Its only needs to be unique per client identifier.

cramforce avatar Nov 19 '15 21:11 cramforce

@cramforce you are right. Client id + page id are probably going to be enough uniqueness.

On Thu, Nov 19, 2015 at 1:40 PM, Malte Ubl [email protected] wrote:

Actually, shouldn't Math.random be completely sufficient? Its only needs to be unique per client identifier.

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/969#issuecomment-158206068.

avimehta avatar Nov 19 '15 22:11 avimehta

Being unique in combination with client ID is fine for our applications, this should just make sure to specify that this is not unique on its own.

Just as a quick note for those who care, you start getting collisions in the low billions of items with 64 bits of entropy (https://en.wikipedia.org/wiki/Birthday_problem): P(collision exists amongst n items getting getting hashed into d buckets) ~= 1 - exp(-n^2/2d) So, for instance, if n = 8 billion (2^33) and d = 2^64, you have the probability of collision at: 1 - exp(- (2^33)^2 / (2*(2^64)) = 1 - exp(- (2^66) / (2^65)) ~= 86%

joshschwartz avatar Nov 19 '15 22:11 joshschwartz

Cool. Will make sure to document.

cramforce avatar Nov 19 '15 22:11 cramforce

[Renamed issue to reflect that this applies to cases other than just ads.]

rudygalfi avatar Nov 23 '15 23:11 rudygalfi

@cramforce What's the status/timing of completing this?

rudygalfi avatar Dec 01 '15 00:12 rudygalfi

#977 is out for review, but hasn't gotten any review love while I was on vacation :)

cramforce avatar Dec 01 '15 00:12 cramforce

Page view id landed.

Exposing the client identifier is next.

cramforce avatar Dec 01 '15 01:12 cramforce

Fixed by #1146

cramforce avatar Dec 13 '15 21:12 cramforce