Prebid.js
Prebid.js copied to clipboard
Prebid Click Tracking
How can I track prebid clicks in GAM? The bidder is AppNexus. Creative is below, but I am unsure where to put the click tracker in the creative tag.
<script>
var ucTagData = {};
ucTagData.adServerDomain = "";
ucTagData.pubUrl = "%%PATTERN:url%%";
ucTagData.adId = "%%PATTERN:hb_adid_appnexus%%";
ucTagData.cacheHost = "%%PATTERN:hb_cache_host_appnexus%%";
ucTagData.cachePath = "%%PATTERN:hb_cache_path_appnexus%%";
ucTagData.uuid = "%%PATTERN:hb_cache_id_appnexus%%";
ucTagData.mediaType = "%%PATTERN:hb_format_appnexus%%";
ucTagData.env = "%%PATTERN:hb_env%%";
ucTagData.size = "%%PATTERN:hb_size_appnexus%%";
ucTagData.hbPb = "%%PATTERN:hb_pb_appnexus%%";
// mobileResize needed for mobile GAM only
ucTagData.mobileResize = "hb_size:%%PATTERN:hb_size_appnexus%%";
try {
ucTag.renderAd(document, ucTagData);
} catch (e) {
console.log(e);
}
</script>
Someone with javascript chops might be able to add some code that listens for click events?
Maybe set a variable like
var gamClickTracker="%%CLICK_URL_UNESC%%"; // this will be resolved by GAM
//pseudo-code!
listenToClickEvents() {
fire gamClickTracker;
}
Do you just want the clicks tracked in GAM, in the bidder reports, or in a Prebid Analytics report?
Tracked in GAM. Thanks!
I don't think that works @bretg as I don't think there is an event to listen to
I think #5796 is more likely to succeed, but requires the ssp to deliver specific markup
I was thinking something like this -- https://stackoverflow.com/questions/2381336/detect-click-into-iframe-using-javascript/32138108#32138108
Prebid creatives are wrapped in an iframe, so maybe there's something we can do to detect clicks on that iframe without affecting the rest of the page?
So I have been digging into this a bit and the
One way seems to be setting the focus and then listening to blur and focus events but when I was trying this with multiple iframes I was getting some weird interactions but could have just been me.
Another way that I seemed to have a bit more success with was defining an object with fields related to different mouse events and then setting those to true or false using different event listeners. You can then build functions off the main object to send the data around.
I haven't been able to figure out how to communicate this back to GAM though yet
That link is fascinating, thanks Bret! There are a bunch of solutions there. I would think we would want %%CLICK_URL_ESC%% to be added to the creative in gam and then passed up in the post message, and secure_creatives.js would need to receive it, does that sound right?
On Thu, Feb 18, 2021 at 8:44 AM Chris Huie [email protected] wrote:
So I have been digging into this a bit and the
One way seems to be setting the focus and then listening to blur and focus events but when I was trying this with multiple iframes I was getting some weird interactions but could have just been me.
Another way that I seemed to have a bit more success with was defining an object with fields related to different mouse events and then setting those to true or false using different event listeners. You can then build functions of the main object to send the data around.
I haven't been able to figure out how to communicate this back to GAM though yet
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/prebid/Prebid.js/issues/6130#issuecomment-781352837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM25Z74TTDULTIHCH32TLLS7UKSXANCNFSM4U3ILZSQ .
A few links and implementations exampled in this issue for reference
I don't see the resolution here, are you closing as 'won't do'
On Wed, Feb 24, 2021, 10:19 AM Chris Huie [email protected] wrote:
A few links and implementations exampled in this issue for reference
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/prebid/Prebid.js/issues/6130#issuecomment-785107635, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM25ZZYOTS2GT63GPUPZGTTAUDHXANCNFSM4U3ILZSQ .
@ChrisHuie - the goal here would be to add some documentation on the site giving an example and/or guidance. If you can post your experiments here, we can discuss how best to document.
docs issue 3124 wasnt merged, why was this closed?
One solution... we could document that the GAM creative passes the GAM click URL like:
<script>
var ucTagData = {};
ucTagData.adServerDomain = "";
ucTagData.clickUrl = "%% CLICK_URL_ESC%%";
The PUC now has access and can do ... something
- if its possible to put a javascript click intercept fn, then that fn can access ucTagData.clickUrl and drop a pixel to it.
- or something else?
IMHO the best thing to do would be that bidders are made aware of this clickUrl
parameter and use it it their respective creative codes. This comes with the advantages that
- click tracking works for a certain bidder either 100% or not at all. At least no guessing
- bidders can document that they support the
clickUrl
parameter - there's no hacky workarounds to make things somehow work
I understand that it may take years until the majority of bidders support it, but it's a viable way to go forward IMHO.
Muki - I don't think we should be updating the bidder's creative if possible. Here's the general direction of what I'm thinking:
- When we add an iframe in PUC and/or core, we add an "onClick" handler to that iframe that runs a javascript function that takes an array of urls and calls an AJAX request for each URL. e.g.
- after that javascript runs, then the broswer passes the click through to the actual creative and that takes the user to the landing page, possibly after a series of redirects.
Difficulties:
- handling safeframes might require a postmessage solution
- where can the click urls come from. Clearly we want the ad server's click URL to be present. But will GAM track their %%CLICK_URL_ESC%% if hit by an AJAX call?
https://docs.prebid.org/dev-docs/publisher-api-reference/renderAd.html#sidebar now documents how the renderAd function already can handle this.
Listening for clicks inside frames seems to only work on desktop(is this true?), which is quite undesirable. I think modifying adm as Muuki suggests is the only possibility?
@dgirardi - you're working in this area with the ${CLICKTHROUGH} macro, right? Can we assign this to you?
Is this covered by CLICKTHROUGH though? that requires collaboration from the creative markup. Or can we drop a pixel without worrying about the "through" part?
Would this work?
- on render, creative passes
%%CLICK_URL_UNESC%%
to Prebid - prebid uses it to replace
${CLICKTHROUGH}
in the markup - if the markup did not contain any instance of
${CLICKTHROUGH}
, modify it to listen for clicks and trigger a pixel on any click, without any "through" URL.
How does "listen for clicks" work? Is that an onMouseClick event on the iframe? Would it work for mobile?
it would be a combination of mousedown
and touchdown
listeners inside the iframe (at the same level where we wrote the markup), that would probably trigger a message up to Prebid which would drop a pixel. It should work on mobile but I will need to do some testing to confirm.