<aside> πŸ’‘ Understanding: This document guides you to seamlessly integrate the Traffic Cop script within your script and ensure that AdSense, GAM, Ad Exchange, and all other third-party ad network codes are compliant and fully functional.

Looking for Measure Mode installation instructions? Use Installation SOP: Traffic Cop Measure Mode for Ad Tech Vendors with In-house Script

</aside>

<aside> πŸ‘‰ Action: Implement the Traffic Cop script into the appropriate section of your own script, ensuring it loads asynchronously to prevent blocking page rendering. Check for errors, verify the script that it is working, and then the third-party ad network ad codes to ensure compliance.

</aside>

<aside> β›” Pitfalls: Ensure that you also adhere to the guidelines of implementing Traffic Cop Block Mode with your third-party ad codes. It can result in performance issues if those are not followed. If the snippets/examples below don’t match the code that you have, please reach out to your MonetizeMore POC.

</aside>

Setup

1. Dynamically Load the Traffic Cop Script

In your JS code, you need to dynamically load the Traffic Cop script (see the sample code below)

function loadTrafficCopScript() {
	// Load the Traffic Cop script
	var trafficCopScript = document.createElement('script');
	trafficCopScript.src = '//c.pubguru.net/pg.site-config.js'; // Replace with actual Traffic Cop script link
	trafficCopScript.async = true;
	// Append the Traffic Cop script to body
	document.body.appendChild(trafficCopScript);
}

NOTE: Load the Traffic Cop script as soon as possible. This ensures Traffic Cop is able to vet traffic as soon as it loads and is able to protect you from invalid traffic early in the flow.

<aside> <img src="/icons/info-alternate_blue.svg" alt="/icons/info-alternate_blue.svg" width="40px" />

The actual code might look different depending on your script implementation. If you have any trouble loading the Traffic Cop script dynamically, reach out to your Traffic Cop POC.

</aside>

2. Implement Block Mode

You need to wrap the part of your code responsible for loading ads inside Traffic Cop. The example below shows how you can wrap your ad load function in Traffic Cop so that ads are loaded only for valid traffic.

// This is your function that makes ad load calls
function loadAds() {
	// Your existing ad loading code
}

// This function makes ad load calls only when traffic is valid
function checkTrafficAndLoadAds() {
	window.pg=window.pg||{};
	pg.atq=pg.atq||[];
	
	pg.atq.push(function() {
		// This code block gets executed after Traffic Cop validates a user 
		// or after a CAPTCHA is solved.
		loadAds();
  });	
}

<aside> <img src="/icons/warning_yellow.svg" alt="/icons/warning_yellow.svg" width="40px" />

Please ensure that all parts of your code which are making ad load calls get wrapped by Traffic Cop. This includes

Example for block mode with GAM tags:

//Before - your raw code in JS

// This is your function that loads GPT script
function loadGptScript() {
	 var gptScript = document.createElement('script');
  gptScript.async = true;
  gptScript.src = '<https://securepubads.g.doubleclick.net/tag/js/gpt.js>';
  document.head.appendChild(gptScript);
}
//After - with Traffic Cop added JS

// This is your function that loads GPT script
function loadGptScript() {
	 var gptScript = document.createElement('script');
  gptScript.async = true;
  gptScript.src = '<https://securepubads.g.doubleclick.net/tag/js/gpt.js>';
  document.head.appendChild(gptScript);
}

// This function makes ad load calls only when traffic is valid
function checkTrafficAndLoadAds() {
	window.pg=window.pg||{};
	pg.atq=pg.atq||[];
	
	pg.atq.push(function() {
		// This code block gets executed after Traffic Cop validates a user 
		// or after a CAPTCHA is solved.
		loadGptScript();
  });	
}

Appendix: Important Reminders