Haseeb Ahmad Haseeb Ahmad - 3 years ago 185
jQuery Question

Google DFP Ad show for click events

I want to show google dfp unit when user click on

navbar


$(document).ready(function () {
var navbar = false;
var navslot = null;
$(document).on('click', '.new_car_nav', function(){
navslot = googletag.defineSlot('/10176910/NavBar', [[250, 250]], 'ad_navbar').addService(googletag.pubads());
googletag.enableServices();
googletag.display('ad_navbar');
});
});


Issue is that it gives an error

Exception in queued GPT command TypeError: $ is not defined


Either we can use jquery in it or not? If no then how can I implement it?

Answer Source

You need to include jQuery, add this to your <head>

<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download