Skip to content
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

Prebid Click Tracking #6130

Open
AStephenson opened this issue Dec 14, 2020 · 20 comments
Open

Prebid Click Tracking #6130

AStephenson opened this issue Dec 14, 2020 · 20 comments
Assignees

Comments

@AStephenson
Copy link

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 src = "https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js"></script>
<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>
@bretg
Copy link
Collaborator

bretg commented Dec 22, 2020

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;
}

@bretg bretg changed the title Prebid Click Tracking - AppNexus Prebid Click Tracking Feb 1, 2021
@bretg
Copy link
Collaborator

bretg commented Feb 1, 2021

Do you just want the clicks tracked in GAM, in the bidder reports, or in a Prebid Analytics report?

@AStephenson
Copy link
Author

Tracked in GAM. Thanks!

@ChrisHuie ChrisHuie self-assigned this Feb 15, 2021
@patmmccann
Copy link
Collaborator

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

@bretg
Copy link
Collaborator

bretg commented Feb 17, 2021

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?

@ChrisHuie
Copy link
Collaborator

ChrisHuie commented Feb 18, 2021

So I have been digging into this a bit and the <iframe> html tag supports global and event attributes so you are fine attaching event listeners to them like some of the above StackOverflow solutions. It seems like people are approaching this in generally 2 different ways.

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

@patmmccann
Copy link
Collaborator

patmmccann commented Feb 18, 2021 via email

@ChrisHuie
Copy link
Collaborator

A few links and implementations exampled in this issue for reference

@patmmccann
Copy link
Collaborator

patmmccann commented Feb 25, 2021 via email

@bretg
Copy link
Collaborator

bretg commented Feb 25, 2021

@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.

@patmmccann
Copy link
Collaborator

docs issue 3124 wasnt merged, why was this closed?

@bretg
Copy link
Collaborator

bretg commented Oct 20, 2022

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?

@muuki88
Copy link
Collaborator

muuki88 commented Oct 22, 2022

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.

@bretg
Copy link
Collaborator

bretg commented Dec 15, 2022

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. <iframe onclick="pbjs.utils_urlhit(ucTagData.clickURLarray)">
  • 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?

@patmmccann
Copy link
Collaborator

patmmccann commented Dec 22, 2022

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?

@bretg bretg removed the needs docs label Jan 5, 2023
@bretg
Copy link
Collaborator

bretg commented Feb 9, 2023

@dgirardi - you're working in this area with the ${CLICKTHROUGH} macro, right? Can we assign this to you?

@dgirardi dgirardi self-assigned this Feb 9, 2023
@dgirardi
Copy link
Collaborator

dgirardi commented Feb 9, 2023

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?

@dgirardi
Copy link
Collaborator

dgirardi commented Feb 9, 2023

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.

@bretg
Copy link
Collaborator

bretg commented Feb 9, 2023

How does "listen for clicks" work? Is that an onMouseClick event on the iframe? Would it work for mobile?

@dgirardi
Copy link
Collaborator

dgirardi commented Feb 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Dev
Development

No branches or pull requests

7 participants