Google Adwords Dynamic Keyword Insertion PHP Script

So, you want to be an Adwords rockstar?

Well then, you'll need to wrap your brain around dynamic keyword insertion.

And I'm not just talking about the basics - just using dynamic keyword insertion in your Google Adwords advertisement. I'm talking about playing with the big kids and using those keywords that appear in your Adwords advertisement also on your web page.

That's right, if you are targeting a specific search terms in your advertisement - make that keyword show up on your landing page. Heck, even have it show up as the title and actual url of your page. Now we are talking.

Maybe instead of talking, let me show you a few things to give you the picture. It will all be crystal clear in just a moment ...

What Is Dynamic Keyword Insertion?

Lets say you are advertising using Google's Adwords program. One of the things you provide for your ad is a list of keywords that you are interested in having your advertisement display for.

For instance, if you were selling "kobe beef", you might want your advertisement to show up on Google's search engine page every time someone types in the words "kobe beef" in the search box on Google.

Same goes for someone searching for "kobe steak" - you want your ad displayed.

With dynamic keyword insertion, every time someone types in the exact search term you are targeting, your advertisement would include those keyword - in bold - on your advertisement.

Here's what the syntax looks like:

{keyword:} - will display the search term or not if there is not a match

{keyword: Default} - will display the search term or "Default" if there is problem displaying the search term. Of course, you can replace "Default" with whatever you like.

Some specific details regarding keyword: (source: Red Fly Marketing )

keyword - No capitalization, all word(s) are in lower case
Keyword - The first word is capitalized
KeyWord - Every word is capitalized
KEYword - Every letter in first word is capitalized
KEYWord - Every letter in the first word AND the first letter of the second
KEYWORD - Every letter is capitalized

More details at Google Adwords

How Do You Do It?

Login to your Adwords account. Create or edit a campaign. Create or edit a Text Ad.

Here's an example of what an ad might look like that uses keyword insertion.

adwords

 

Notice that use of the {KeyWord: Default} in the Headline and Description line 1.

adwords keyword insertion

 

This is the important part for getting the search term to show up on your web site. Use the {Keyword: Default} as part of your Destination URL. In this example, I have added my top level domain, http://www.DaveWooding.com/ followed by the keyword insertion expression followed by ".html". Note that I have added a dash, "-", in between my default word.

adwords dynamic keyword insertion

 

Display the Adwords Search Terms On Your Page

At this point, somebody clicked on an Adwords ad of yours, something that might look like this:

adwords dynamic keyword insertion

 

In this case, the search term is "kobe steak". A visitor that clicks on that advertisement would be sent to this url, http://www.davewooding.com/kobe%20steak.html.

If someone searched for "kobe beef" the advertisement would look like this:

google adwords dynamic keyword insertion

 

On To Your Web Site

Now that you have setup your Google Adwords advertisement to use keyword insertion, it is time to separate the men from the boys, the women from the girls, the ... you get the point.

Time to play big. You want your site to display an appropriate page for each of those particular search terms. Sure you can do it the old fashion way and grunt it out - create an individual page for each and every possible search term.

Or you can do it the right way.

Using PHP or some other scripting language that allows for extracting information about the referring page - the referring page that uses dynamic keyword insertion. Ding, ding, ding <<<--- important

First, assuming you are working from the top level domain, i.e. - http://www.example.com, you will need to add or modify a .htaccess file to include the following:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+).html?$ index.php?q=$1 [L]

I'm going to assume that if you are reading this far into the article that you are willing to use php files instead of plain html file (otherwise you will need to include additional code in your .htaccess file, specifically "AddType application/x-httpd-php .htm .html").

Very simply, the chuck of code above says to turn on the rewrite engine, reference to the root directory, the rule that follows is applicable if the file or directory referenced does not already exist, then grab all the info after the domain but before the .html extension <- this is our dynamic keyword insertion stuff courtesy of Google Adwords.

Take that information (the dynamic keyword info), shove it into memory - which we will call "dollar one" = $1 and send it over to the index.php file as part of the "q" query string.

You like that techo jargon?

The PHP Code That Displays Adwords Search Terms

... on your site.

As I mentioned, you will need to be using php files for this to work (or you can modify your .htaccess file to accomodate).

At the top of your index.php file, the code should like like this:

google adwords dynamic keyword insertion

 

This chunk of code checks to see if any information has been passed over via the "q" query string (remember the .htaccess grabbed any info between the top level domain and the .html and sent it over as part of the query string parameter).

If there is info, then that information gets assigned to a variable called $replace (after it replaces any dashes with whitespace - assuming there are any dashes).

If no query string info is present, no problemo, there is a default value set previously - "kobe beef" in this case.

google adwords dynamic keyword insertion

 

Next a few other variables are set based on the what is in $replace. $title is the same as $replace with the exception that the first character of every word are capitalized. $h1 is the same as $replace except that just the first character is capatilized.

google adwords dynamic keyword insertion

 

Following the php script part of the index.php file is plain old html code - with the $title and $h1 variables thrown in.

google adwords dynamic keyword insertion

 

This is how you display the Adwords search terms on your site.

What's Next?

We are only scratching the surface of what is possible here.

Lets just speculate that you have a datafeed that you want to create individual landing pages for that you want to use PPC to drive visitors to. Or you are a Clickbank affiliate that wants to use Adwords to promote products and you want to use the Clickbank datafeed? Or you have an Ebay store that uses a RSS feed from Ebay to display items for sale that could afford pay per click marketing?

What you have seen here is perfect for creating relevant, high quality score landing pages for using Google Awords with.

Stay tuned, or sign up to get on the mailing list, for the next article which will show you how to integrate a datafeed - like SpeedPCC - with dynamic keyword insertion.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Verify A Web Page Exists With PHP


Check To Verify Your Site Exists

I'm getting ready to open up the offer I made a couple months ago - to build you a gardening database driven website.

Before I do that, I want to make sure you are ready. One thing I will ask you is if you have a website ready to go ... and I have a script that will verify.

The reason I am doing this is so that when you place your order, we can get your site setup and ready to go in a short amount of time.

Here's part of the script I will have when the order page goes live next week:

Domain:

Thanks.

Dave

P.S. - If you have any questions, please use the comment section below to ask, thanks.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Split Testing Google Adsense The PHP Way

Or "The Poor Man's Split Testing Method".

There's no right or wrong way to do this. Darren Rowse made a post about split testing Google Adsense and showed how to do so using channels and a little javascript.

Like a lot of things, there are other ways of accomplishing the same thing.

Enter PHP, that fancy web scripting language that gives you the ability to do some pretty neat tricks.

The code snippet below allows you to split test your Adsense by day. Instead of having to setup separate channels to split test, just login to your Google Adsense account, create two versions of the Google Adsense code you want to test, paste those two versions into the PHP code shown below, put that PHP code in an include file on your site, and call that include file in your web page. Then, if you want to see how you are doing, go back to your Google Adsense account and look at your results by day.

O.K. maybe that was a lot of stuff to do.

If you have a PHP enabled web site and you are not using PHP includes, tsk, tsk.

All of the even numbered days (even numbered according to PHP) will display one version of your Adsense code while all of the odd numbered days will show another version of your Adsense code.


<?php

if (date("z")%1) {

?>

<!-- Google Adsense #1 goes here -->

<?php

} else {

?>

<!-- Google Adsense #2 goes here -->

<?php

}

?>


The most important part is the "if" statement, the code that checks whether today is an even or an odd numbered day.

In this PHP example the "z" represents the day of the year.

The date("z")%2 < 1 checks if today's number modulus 2 is less than one (which asks if today is an even numbered day), then do whatever is between the set of squirly braces - the "{" and "}" - else do whatever is between the next set of squirly braces.

The whatever I am referring to is display your Adsense code.

By the way, there is nothing to prevent your from putting anything between the squirly braces.

There are some limitations to be aware of for sure. Namely, you still need to generate two versions of the Adsense javascript code to include on your web site. Also, if you want to get a better understanding of your results, you will need to download the results and group the data by even or odd day. I don't even know if Google allows for an easy way to get your Adsense results - I'm not even going to login to find out.

But, for a quick and dirty way of split testing your Adsense results, this PHP code will do the trick.

Extra: You don't have to just use the day of the year ("w"), you could just as easily use day of the week ("w"), hour of the day ("G"), day of the month ("j") - or some combination. Whatever your mind can conceive and believe it can ... oops, that's for a different topic :)

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Advertisements For Your Affiliate Datafeed Site

Even easier than adding articles is adding advertisements to your website.

You will need to edit the advert.php.

Paste in the html code for your advertisement. Save the file and upload the advert.php to your web server. That's it.

If you want to add an autoresponder email capture form - same thing. Edit the advert.php file and paste in your autoresponder html code.

You can add as much html code to your advert.php file as you want - THE SCRIPT will display whatever html code you include (it will not parse PHP code though).

A 3 minute video - music included free of charge - shows exactly what to do.

Here is the video ... CLICK HERE >>> advertisement video.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Affiliate Datafeed Sites Ready

You read that right. Datafeed affiliate sites are ready for you.

Thanks to the beta testers that participated - I was able to check THE SCRIPT out on sites as the homepage, in a subdirectory, and as a subdomain.

Here's a brief tour of what these sites look like.

Home Page

The home page randomly selects an instock image from the database to display on each page load.

What remains consistent is the links to the categories - the gateway to the 1,400 unique pages that make up this site.

home page

Category

Lots of content on this page. Each category page will display a random, instock item with image at the top of the page, followed by a list of other items from the same category. Some little programming *twists* I put in include:

  • sorted by highest to lowest price
  • Decreasing amount of information per item - the first few items display the most amount of information, farther down the list, the items have less information about them, until you get the the last few items - all there is at that point is links. Why did I do this - to be different. I don't want these sites to be run-of-the-mill datafeed sites that are practically identical to other datafeed sites

category

Product page

Specific information about each instock item in the datafeed - includes a image, price, title, description.

product

What's unique about about these pages is:

  • Randomly arranged sentences - the sentences are not the exact same structure as what is provided - THE SCRIPT rearranges the results and displays them in a different order each time the page is refreshed ...
  • ... which leads to this, THE SCRIPT has a cache feature so the results remain the same for each dynamically generated page. During setup, the cache is either turned on or left off (I recommend having it on). If on, then specify how long pages are cached for before being regenerated. I don't see any reason to set the cache for anything less than 30 days.
  • Something you should know, there are actually 4,000+ items in the database. Unfortunately, most of the products are out of stock. That's a lot of perfectly good information going to waste. So what did I do, I include a random item description from an out of stock item from the same category for the same reason I added a few twists to the categories - to be different.
  • Also, the side bar - besides containing links to the categories - also includes links to random items in the same category

Search

Included a "smart" search feature - well, maybe not as smart as Google, but smart enough to almost guarantee relevant results showing up.

Here's how it works, say you type in "apple". THE SCRIPT will randomly pull results that have the word "apple" show up in the title. If THE SCRIPT doesn't find any results, then it makes a second pass through the database looks for the word "apple" in the description. Pretty smart, huh?

search

Ready To Go

A simple, powerful script that displays results from the datafeed in a unique fashion - that's what THE SCRIPT is.

P.S. - If you want a "behind the scenes" view of how the code works for this datafeed site, visit the link, http://www.youtube.com/watch?v=PLeGbqEb9L4.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Garden Database Template

The database driven affiliate website is coming along ... if I do say so myself.

I am back from spring break 2008. Before you start thinking fun in the sun and wild parties, guess again. The family went down to southern Utah and visiting a couple of state parks, Kodachrome and Escalante, to get a little warmth in the desert. We camped out in the tent trailer - the first couple of nights were chilly - in the teens, 15-20F. But the days were very pleasant, 60-70F, and sunny.

Like I said, THE SCRIPT is moving along. I banged out some code tonight to have it pull results from the database.

database template

Note, the PHP code above should look familiar. It is a slight modification of the query code I created previously. It takes a word and finds one item in the database that has the same word, and pulls out the information from the MySQL database: title, affiliate link, image link, price and description.

Creative Code

The second chunk of code is where I get a little creative.

random database items

I am randomly choosing 5 to 10 additional items out of the database. This is for a sidebar menu that leads to other products.

Keep in mind that this is first pass coding for this affiliate site. I'm just randomly requested information - not taking into account whether the item selected is even in stock.

I'm thinking it would be worthwhile to have some hard coded links in place - specifically to categories like "trees", "shrubs", "flowers" - that kind of thing.

Print Out The Results

Three things in a row.

database template results

This PHP code does three things.

  1. Opens the template and reads it in to the script
  2. Makes replacements - substitutes the tokens (as an example, %%TITLE%%) with database results
  3. Prints out the results

There it is - let me know what you think so far.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Unique Datafeed Content

There's a problem with datafeed affiliate sites - at least it is a problem if you want your sites to stand out from all of the competition - duplicate content.

Who do you think will rank higher in the search engines for specific terms that you might find in your datafeed? Probably the merchant. If this happens, then your site is less likely to get the click that gets the affiliate sale.

So what to do, what to do - let me think. Hmm.

Let's get a little creative with what the merchant gives us, shall we.

Here's an example entry that we can use from the affiliate's datafeed.

affiliate datafeed

I was planning on using the second line, the one that says "American Beech" as the title. What is to stop me from also adding the word "Tree" found on the 12th line down to the title. Nothing really. I can make the affiliate script combine portions of the datafeed and mash it up to create a new title. Pretty cool, huh!

Or how about this idea.

Instead of using the "Dahlia - Dinnerplate - Magic Sunrise" as the title, why not (1) get rid of the dash (-) and also rearrange the words to read "Magic Sunrise Dahlia Dinnerplate"? I can already see the PHP code to do that.

rearrange datafeed

Want in on a big secret - on how I am going to make each site affiliate datafeed site that I create unique?

What secret little piece of PHP code that I have planned for making certain that no matter what, each site I build is not identical to any other site.

Ready? Here it is ... modulus.

I'll explain later :)

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong

Random Images

I said I would do some work on the foundation of this weblog.

See the sidebar over there, the one with my lovely mugshot? Yeah, that one. I hardcoded some of the info in there, in particular the section that includes my picture.

If you were to hit the refresh button, another picture would show up. Magic, huh?

Not really, but it did use a little PHP to get that impact.

Here's what I did.

1) Login to the admin section.

2) Click on Presentation.

3) Click on Theme Editor, then for this theme, I clicked on sidebar.php.

Here's where the PHP magic occurs.

randomize the images

That image might be a little tough to see, here's the important part.


<img src="http://www.davewooding.com/images/<? echo rand(1,6); ?>.jpg">


Note the php echo statement in there. Before I explain, I should tell you that I created 6 images to use for this and labeled them 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg and ... drumroll, please ... 6.jpg.

That php echo statement in there with the rand function says to pick a random number (1 thorugh 6) and print that out. Notice that it prints out in the middle of an image source statement - that's how I get a random picture to show up.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • StumbleUpon
  • MisterWong