Google DFP Ad show for click events

303 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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>
0
On

You are missing jQuery library, you need to include it into the head section before any other library includes.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Hope this will help you.