Setting up Moat and DFP

Setting up Moat and DFP isn't as straightforward as I would like. Here is a guide to getting it done

It may be how new I am to using Google’s DoubleClick For Publishers but I had a bit of a hard time getting our Moat script working.

If you have found this post I am going to guess you are facing similar problems. Here is what I did to get Moat working.

DoubleClick for Publishers

DoubleClick for Publishers, or DFP, is Google’s platform for delivering ads you have created yourself or imported from third parties. Moat does work with other things, this short guide just covers DFP integration.


Moat is a tool you can use with DFP to improve the tracking of your adverts. Specifically to track the view-ability of your advert. View-ability is becoming an important metric for businesses who serve adverts to be able to report on.

Getting the two to play nicely

The main part of the ad which appears on your website is ‘the Creative’.

In order to get Moat playing well with our creatives I had to create my own custom User-defined Template.

You can do this by clicking on;

  1. Creatives
  2. Creative Templates
  3. New Creative Template

Once here there are only a handful of more things you need to do;

  1. Name your template. This should be something memorable, you will be referring to it every time you upload new creative from now on.
  2. Add any custom variables you need. For our uses we needed an image, some dimension data for the image and the URL we wanted the image to go to when clicked.
  3. Add your snippet of code. I have included some sample code below.
<!-- main advert -->
<a href="%c[%URL%]" target="_blank"><img width="[%width%]" height="[%height%]" border="0" src="[%imagefile%]"></a>

<!-- moat code -->
<noscript class="MOAT-id?moatClientLevel1=%eadv!&moatClientLevel2=%ebuy!&moatClientLevel3=%eaid!&moatClientLevel4=%ecid!&moatClientSlicer1=%esid!&moatClientSlicer2=%epid!&zMoatPS=%%PATTERN:pos%%"></noscript>
<script src="!&moatClientLevel2=%ebuy!&moatClientLevel3=%eaid!&moatClientLevel4=%ecid!&moatClientSlicer1=%esid!&moatClientSlicer2=%epid!&zMoatPS=%%PATTERN:pos%%" type="text/javascript"></script>

Once you have your custom snippet when you add new Creative you can select from your newly created template from User-defined Templates.

Recent posts View all


The best way to test model scopes in Rails

Learn about Rails scopes and how to best test them with both Rspec and Minitest


Finding out what called a Ruby method

A quick way to understand what is calling your code using the caller method