Question

I am looking to see if someone can provide me the php code in order to grab the utm_source value from a URL and insert it as a targeting criteria in a Google DFP tag.

Not sure how much more info you need to help but this is sample code of what I am using to grab the wordpress categoery. This is going into the DFP perfectly. Need something that will do the same but with the utm_source of the URL

 <?php
    $category = get_the_category(); //Get categories
    echo 'googletag.pubads().setTargeting("category", "' .htmlspecialchars($category[0]-            
    >cat_name) . '");'; //Output first category

    ?>
Was it helpful?

Solution

This is actually very simple to do. First define a dynamic key-value (let's call it utm) in DFP Admin. Predefined would not work in this case. Then as Marty said get the utm_source and output it as follows:

$utm = $_GET["utm_source"];
echo 'googletag.pubads().setTargeting("category", "' .htmlspecialchars($category[0]->cat_name) . '").setTargeting("utm","'.htmlspecialchars($utm).'");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top