Reputation: 11
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/11589435/serptest300x250', [300, 250], 'div-gpt-ad-1345189271658-0').addService(googletag.pubads()).setTargeting("TargetedKey","Targetedvalue");
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
I have an ad slot on my website currently running an ad campaign using Google's DFP.
Current client has a set of keywords, because of which we can show him his own creatives.
Recently, we have signed up another client who would like to feature in that same ad slot, however, for a different set of keywords altogether
Question: How do I tweak the piece of code above so that I can look up on the keyword that is entered and show an ad from a specific ad campaign?
'TargetedKey' = The Name of the client that we have signed up
'Targetedvalue' = A keyword that he has signed up for. (Basically, he has about 10 keywords, which, when a user performs a search on my website, I am managing to enter in the 'Targetedvalue' bit)
p.s. I have picked up DFP in the last 2 months and have been managing ad-campaigns voluntarily for my organization. I'm not very good at programming either.
Upvotes: 1
Views: 3101
Reputation: 185
I hope u are looking to get the ads based on some target keyword.
Can you try with below way i.e pass the keyword in settargeting() method
googletag.pubads().setTargeting('tags', 'Male'); // where Male is the target keyword
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
Upvotes: 0
Reputation: 10880
This is more to do with javascript than DFP but the following should allow you to test different key word combinations...
Load this page with your key and values comma separated in the URL like so: http://yoursite.com/?key=test&values=test 1,test 2,test 3
<html>
<head>
<title>DFP test</title>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type="text/javascript">
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null) {
return "";
} else {
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
var key = getParameterByName('key');
var values = getParameterByName('values').split(',');
googletag.cmd.push(function() {
slot = googletag.defineSlot('/11589435/serptest300x250', [300, 250], 'adunit').addService(googletag.pubads()).setTargeting(key,values);
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<div id="adunit">
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.display('adunit');
});
</script>
</div>
</body>
</html>
Upvotes: 2