-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Add element viewability triggers for amp-analytics #1297
Comments
cc @cramforce who mentioned implementing this by dispatching DOM events on AMP elements when they become visible and stop being visible. |
The main goal of this issue is to enable element level measurement of viewability. For best performance and to keep user experience good, the APIs mentioned below only work for amp-* elements. We already do a lot of the required calculations for these elements and additional work should not affect the performance severely. The API/configuration comes into play when the trigger is set to fire on The API allows for additional conditions, all of which have to be true, that determine whether the trigger should be fired or not. API configuration:Visible PercentageThese conditions keep track of the amount of element visible in vieweport at any given time. They get triggered when the percentage of element visible is between min and max (if specified). The properties that enable these conditions are named Continuous TimeThese conditions keep track of the amount of time (any part of) an element has been in the viewport and fire when the time is between the minimum and maximum configured time. These conditions are configured using Total TimeThese conditions keep track of total time for which any part of an element is on screen and fire when the time is between minimum and maximum. These conditions are configured using UnloadAs the name suggests, this condition is true only when the page is in the process of being unloaded. Since using Additional implementation details:
Summary "visibilitySpec": {
"selector": <element id>,
"visiblePercentageMin": <%>,
"visiblePercentageMax": <%>,
"continuousTimeMin": <milliseconds>,
"continuousTimeMax": <milliseconds>,
"totalTimeMin": <milliseconds>,
"totalTimeMax": <milliseconds>,
"unload": true
} ExamplesvisiblePercentageMin: 50
continuousTimeMin: 1000 This should fire as soon as at least 50% of the ad has been on the screen continuously for 1 second. visiblePercentageMin: 1
totalTimeMin: 1000 This will fire after at least 1% of the ad has been on the screen for a total of 1 second. unload: true
visiblePercentageMin: 50
continuousTimeMin: 1
continuousTimeMax: 999 This will fire when an ad is at least 50% on screen for at least 1ms, but it is unloaded before it can get to 1s. Complete tagging example <amp-analytics>
<script type="application-json">
{
"requests": {
"format1": "https://myanalytics.com/id=${id}&ct=${continousTime}&vpn=${visiblePercent}",
"format2": "https://myanalytics.com/id=${id}&unload=1&ct=${totalTime}&vpx=${vpx}"
},
"vars": {
"id": "123456"
},
"triggers": {
"continuousVisible": {
"on": "visible",
"request": "format1",
"visibilitySpec": {
"selector": "adsElementSelector",
"visiblePercentageMin": 50,
"visiblePercentageMax": 74,
"continuousTimeMin": 1000,
"continuousTimeMax": 2000
}
},
"unload": {
"on": "visible",
"request": "format2"
"visibilitySpec": {
"selector": "adsElementSelector",
"unload": true
}
}
}
}
</script>
</amp-analytics> Additional variables to be supportedDescriptions of the following are still pending. Names should give an indication of what they are about. minVisiblePercentage maxVisiblePercentage totalVisibleTime continuousVisibleTime firstSeenTime lastSeenTime firstVisibleTime lastVisibleTime Still pending:
/cc @cramforce @btownsend |
@avimehta this all sounds good. My only concern if this statement is sufficient:
It's obviously correct that amp- elements would give the best performance, but I'd like to make sure that it solves the problems it needs to solve. |
Currently, This is needed for amp-ads and people might want to implement it for videos, carousel and possible other social widgets. Not sure if text content needs to be tracked at this granular level. Maybe scroll-tracking solves that part? |
No, now I get it. Surely then |
👍 This would definitely be awesome to add. Regarding only supporting amp- elements, I agree that we can cover a lot of ground that way, but certainly there are other use cases? For instance, maybe you use a |
From reviewing the PR: Maybe it is just me, but I find the usage of the |
@cramforce I read it as a set of conditions and the trigger fires when the values are between @surfcasper any other suggestions for the names? |
@avimehta So if max is surpassed it doesn't fire? Or does it fire when max is reach or on unload? |
Lets take the example of
As soon as the element has spent 1 continuous second with between 50 and 74 percent (inclusive) of its pixels on the screen, this will fire.
Lets change the example to following:
This trigger will fire when all of the following conditions are met:
|
@avimehta #1608 (comment) inspired me to ask if you will be able to track viewability on non-(amp-*) sub-elements of amp- elements. For example:
Can you track the |
I think it will be trivial to do that but I am not going to do it in the beginning. The calculations we are doing are costly enough that doing it for a subset of elements might affect performance. If we allow all elements to be tracked like this, we will be opening the floodgates. (also, doing these calculations for non-amp elements is costlier than for amp elements.) |
This allows specification of vars like `veritcalScrollBoundary` etc. These vars only make sense when particular types of triggers fire and the valuer is based on the trigger config. Fixes ampproject#2031. Also helps ampproject#1297
Rolling into the next milestone |
Would it be possible to add AMP_SELECTOR_RIGHT/BOTTOM to go with AMP_SELECTOR_X/Y so we can get the full box? If not, what about AMP_SELECTOR_WIDTH/HEIGHT? |
Either of those work but I find Width/height a bit more readable. I'll go with that if you don't mind. |
width/height will work fine. Thanks! |
Does unload trigger need its own issue? |
Or perhaps #2487 covers it? |
FYI: I opened #4449 to track visibilitySpec supporting non- |
Offshoot from #871.
We currently support a document viewability triggers in amp-analytics. This request is to support triggers at the element level.
cc @avimehta @btownsend
The text was updated successfully, but these errors were encountered: