Adwords Dynamic Keyword Insertion using a Whitelist

Sorry if this has been posted, I kept getting a page error when doing a search on the forums.

I;m trying to include Adwords Dynamic Keyword Insertion into my landing page. That in itself is straight forward. However the tricky part is only using it on certain keywords, otherwise a default keyword would be used. So for an example, someone searches for Boston Real Estate, the landing page would insert the word Boston, but not Real Estate. I would build a white list of Geo keywords to insert instead of building 50 city web sites.

I have not seen this before and could not find any example in my Google searching. Is there a way to do this with PHP programming?

How are you getting the keywords on your page? My (extremely limited) understanding of Adwords Dynamic Keyword Insertion is that it actually takes place on your ad.

Also, can you be a little more specific about what you’d like to end up with? I assume what’s happening is you’re getting a string of words (e.g., “Boston Real Estate”) and you’d like to end with a string that just has the city name (“Boston”), but I wasn’t quite sure.

I can grab the KW parameter from the URL coming from the ad. I can then echo that on the page anywhere. The problem is, it brings in the entire phrase. So in some cases it does not make sense to show the entire search phrase the user typed. For example, if they typed in Boston MA Houses For Sale, I would not want that entire phrase to be displayed on my page.

What I would rather have displayed is just Boston using a white list. That way, I can include that keyword with my existing Title tags and H1 tags, that already include a partial phrase like Real Estate Deals.

I hope that makes more sense.

After a couple of hours of searching I ran across one snippet of code. There was not much explanation on the code. For example, the ‘some default’, I have no idea what to put in there. The ‘kw’ is what is being pulled from the URL. Does this look correct? Would I need to adjust the code more to meet my needs?


<?php
$allowedKeyWords = array( 'Boston', 'New York', 'Miami' );
$kwval = 'some default';
if ( isset( $_GET['kw'] ) && in_array( $_GET['kw'], $allowedKeyWords ) ) {
$kwval = $_GET['kw'];
}
?>

<? echo $kwval ?>

The only problem with that code snippit you found is that it assumes that the entire keyword string you have is the city name. It doesn’t filter out non-whitelisted words.

(Also, by the way, the “some default” is for if no dynamic key words were sent to your page at all. It’s up to you to decide if that’s an eventuality you want to plan for.)

To allow for multiple-word city names, you could store all of the cities you’re looking for in an array, turn that array into a regular expression, and see if you find any matches:


$dynamic = $_GET['kw']; // 'Boston Real Estate'
$whitelist = array('Boston', 'Chicago', 'New York');
$whitelist = '~\\\\b('.implode('|', $whitelist).')\\\\b~';
$matches = array();
preg_match($whitelist, $dynamic, $matches);
$city = $matches[0]; // 'Boston'

That worked great. Thank you for your help.