How to Implement DFP Ad Targeting on Joomla Sites

Lately, we have been working increasingly on marketing (from a very technical perspective), specifically on ad targeting. Essentially, our clients are being pressured by their own clients to target visitors with matching ads. For example, if someone is a big reader of car articles on a news website, then he will be targeted with car ads (instead of just throwing random ads at the person and hoping he’ll be interested in one of them).

Google Adsense does this automatically. DFP (DoubleClick for Publishers), however, needs to be told how to target ads, which is typically done using key-value targeting.

So, what is DFP’s key-value targeting?

In short, key-value targeting in DFP consists of some variables and their values passed from the application (in our case the Joomla website) to the ad server, which searches the inventory for a matching line item, eventually prioritizing (and displaying) the ad belonging to the line item. Yes, we know that it looks like gibberish at first glance, but let us explain by giving you an example…

Let’s say you have a news website, and a client representing a car company who wants to advertise on your website. The client wants you to target people who read a lot of articles about new cars with their ads. So, what do you do? First, you login to your DFP account, and then you do the following:

  • Click on Inventory on the left panel, and then click on the Key-values link.
  • Click on the “New Key” button, and then fill in the name of the field, such as “CarTarget”, and the possible values, such as “Y” and “N”.

  • Go to the line item of the ad (we are assuming that you have already created the ad unit, the line items, and the creatives), and then click on Settings.

  • Scroll down to the bottom of the page, and then click on the Key-values link (under the Add Targeting section).

  • In the Select a key input box, choose the CarTarget variable that you have just created, and then, in the box just below it, enter “Y” (this means that this line item will only display when CarTarget is set to “Y”).

  • That’s it!

Of course, now you will need to pass the CarTarget variable to DFP from the Joomla website (or any web application) using DFP tags. Here’s how we do this:

  • We first create a database table called dfp_targeting that has 3 fields: userhash, keyvalue, and counter (you will later understand what each of these fields is).
  • For every visit, we check the cookies for a cookie called userhash, if it exists, we increase the counter of the value of the userhash in the dfp_targeting table by 1 where the category field matches the current category being viewed by the user. If such a row doesn’t exist in the table, then we create it, and we set the initial counter to 1.

    If the userhash cookie doesn’t exist, then we create the cookie and we set its value to a 64 character hash, and, on the next visit, we store that cookie in the database (along with the category field and the counter field, which are set to the current category being viewed by the user, and the number 1, respectively).

  • Once a user visits the website with, say 50 as the counter for the “Car” category, we set the CarTarget DFP key to Y and we push this information to DFP using the following JavaScript code:

    googletag.pubads().setTargeting('CarTarget', 'Y');

    Note: We implement all the server/client side code in the article layout override of the Joomla website (e.g. the file templates/[template-name]/html/com_content/article/default.php).

  • That’s it!

Once the above is done, the Joomla website will start displaying targeted ads to regular readers of the Car category.

We hope that you found this article fun and informative. If you need help with implementing DFP ad targeting on your Joomla website, then please contact us. Our fees are super cheap, our coding is super clean, and we are super fun to work with!

No comments yet.

Leave a comment