简体   繁体   中英

Google DFP Listener Event for click events

I am using the following eventListener to get certain output from gpt for each available slot

    googletag.pubads().addEventListener('slotRenderEnded', function(event) {
        gptForForm[count] = [ event.creativeId, event.lineItemId, event.size[0] + 'x' + event.size[1] ];
        count++;
    });

Now I want create an eventListener that will let me know when someone clicks on an ad, I tried the following to no avail

    googletag.pubads().addEventListener('click', function(event) {
        console.log('this lineItemID: '+event.lineItemID+', size: '+event.size[0]+','+event.size[0]+' clicked!!');
    });";

I know I can get a report from DFP but we are trying to collect this data right away and real-time CTR and Clicks without having to check the report every single time. Are there any suggestions that I have not tried?

The short answer is - you can't (with JavaScript). There is no "click" action in the Google Publisher Tag (GPT).

Additionally, you can't set a click event on an iFrame without access to the DOM inside the iFrame. Unless you are using all friendly iFrames, you won't be able to.

Another (and likely better) option is to use the DFP API .

Another option is to set up your own redirection URL ( http://example.com/path/to/dfp/redirector ) that you would need to prepend to the URL the ad needs to redirect to (your redirector would register a click then redirect to the ad's URL). So you would need to add your redirection URL before the ad's URL in every creative you make in DFP (not even sure if this would be a violation of the DFP terms of service [TOS]). You would not be able to detect a click within the browser/client using JavaScript but it would allow you to register your own clicks in a server. This would require server resources on your part so make sure your hardware can handle registering the click and redirect quickly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM