Dynamic Keyword Insertion For Landing Pages

Ian Lurie


I spent part of today being puked on. Not the way you’d expect this blog post to start, I know, but I had to get that off my chest. For the last 3 days, I’ve had the flu. My son had it for 2 days, too. It was a bad cold for us. My daughter decided to break with tradition, though. So this post may occasionally include delirious ramblings as I’m still running a fever and feel like Wesley Snipes just did my taxes.

If you work in Google Adwords or other pay-per-click engines, you’ve likely heard of dynamic keyword insertion (DKI). It lets you use a variable to include whatever keyword a searcher uses, instead of your own. Using DKI, a headline in a paid ad for happy drugs that make the little purple elephants that keep circling my laptop go away:

Great {keyword: Nyquil} Here
Buy flu medicine online and get it
delivered before you go insane.
IansSubconscious.com/{keyword: Nyquil}


Great Tylenol Here
Buy flu medicine online and get it
delivered before you go insane.

if I search on “Tylenol”, instead.

It’s a known fact that searchers are more likely to click on an ad that includes the exact phrase on which they searched. So dynamic keyword insertion is an essential component of any PPC campaign. Note that there are some hazards in DKI, including my undying scorn, so be careful.

Taking Dynamic Keyword Insertion Beyond the Ad

Apply DKI to your landers, though, and you’ll get even better results. Say you have a landing page with a headline:
Get Yer Flu Medication Here

If I searched for ‘Tylenol’, seeing ‘Flu Medication’ may or may not hold my attention. If you can show me this, though…

Get Yer Tylenol Here

…you’ve got me as a customer.

You could do this by creating a different landing page for every drug, as well as a separate ad and ad group. Good luck with that.

Or, you can do a little simple coding and set up dynamic keyword insertion. Here’s how you do it:

1: Pass the keyword along

First, you have to make sure the keyword that triggered your ad gets passed along to your landing page.
In Google Adwords, you’d add something like this to your destination URL:

?kw={keyword} (if there’s already a ? in your destination URL, use an ampersand & instead)

2: Set up your lander

Create your landing page as you normally would.

3: Add the tricky stuff

Now, pick your favorite web programming language. If you don’t know any, pick your favorite web programmer.
They’ll need to add some code that inserts the keyword into the lander in strategic places. In PHP, it might look like this:

$val = $_GET[‘word’];
If you’re suffering from <? =$val ?> you think this text is talking to you right now.

If I mangled this code please let me know. I am, at best, a mediocre PHP hacker.

4: Plan for the worst

No matter what you do, folks will find a way to type in some ridiculous combination of words that makes your page read like a David Letterman monologue:

If you’re suffering from hemmorhoids you think this text is talking to you right now.

So, you’ll probably want to put something in place to catch evildoers who want funny screen captures for their blogs.

The Benefits

Dynamic keyword insertion on your landing pages has several benefits:

  • It makes your pages more compelling. Your visitors will see a page customized just for them. We humans are egotistical beasts. We like it when things work just so. If you want a quick conversion rate improvement, DKI is one way to get it.
  • It improves your quality score. By having the right keywords in place on your lander, you improve your quality score. I recently added DKI to a landing page and saw the client’s quality score jump from 5 to 7 on every keyword in their ad group.
  • It makes you into an Adwords Ninja, much like the little green ninja that are jumping around my home office right now squeaking “Oompa loompa loompity doo….”.

Where to go from here

I’m going to bed.

You can learn more about dynamic keyword insertion on landing pages, and even get some code snippets that’ll help you get started, on these great sites:

Dave Wooding has a great tutorial about doing this in PHP.

Hamlet Batista has written a Python script that does the same thing.

We wrote an extensive guide to getting started in Google Ads and PPC Marketing, check it out.

I’ve actually written my own script in ColdFusion (laugh at ColdFusion and I kick your ass). If folks are interested I’ll post it, as well.

Start call to action

See how Portent can help you own your piece of the web.

End call to action


  1. That was simplistic method to do this. It works, but in long term it has problems, especially if you are working with organic listings as well as PPC campaign.
    Better approach is fetching related content from database and building more targeted content. In your example, fetching Tylenols description, pricing, etc. to make original page instead of generic one. This helps against jokers too.

  2. Nice tip.
    Dynamic Keyword Insertion is a great way to keep your ad and on-page copy targeted without having to manually create dozens (or hundreds) of landing pages for every separate keyword.
    This is a crucial technique to add to your pay-per-click repertoire.
    If you want to get really fancy you can set up automation for images on that landing page as well – but you’ll need to compensate for possible misspellings/variations in the search string. Still, for a long list of product/keyword variations, it makes sense.
    Get some rest!

  3. Okay, this is pretty interesting. As Giedrius said, you can go way further by creating completely dynamic landing pages based on the keyword. I think that can give much more effort instead of only replacing one keyword.
    Didn’t hear of this before, thanks!

  4. Hi there – great work 😉
    Do you have CFML version you could post? Im not laughing about CFML, I’m working with CFML everyday 🙂
    Kind Regards

  5. @Peter I do but it’s ancient – CF 5 or older. I recommend reading up on cgi.http_referer – if you use that variable plus a basic CFIF you can get the same result.

  6. if I use KW instead of kw in the code
    on my landing page will that then make the
    keyword show up in large case font?

  7. Since you asked…
    Your example PHP code is vulnerable to an XSS attack.
    There are two important rules when dealing with user input:
    1. Filter input.
    2. Escape output.
    In your case, following rules 2 could solve most problems:
    <?php echo htmlentities($val); ?>
    But if you want to sleep well, go for rule 1 as well and use a whitelist:
    $allowedKeyWords = array( ‘Tylenol’, ‘Acamol’, ‘Aspirin’ );
    $val = ‘some default’;
    if ( isset( $_GET[‘word’] ) && in_array( $_GET[‘word’], $allowedKeyWords ) ) {
    $val = $_GET[‘word’];
    In any case you should still use the code for escaping output.
    DISCLAIMER: I didn’t actually test this code, it’s all typed out from memory. Also, although unlikely, there still may be security problems, depending on the context.
    I can appreciate the need to show short code to get ideas across, but many novice users will use the code verbatim. At the very least output escaping should be there, but I’m pretty sure that as a web site owner you’d rather not allow the (virtual) creation of pages with just any content.

Comments are closed.

Close search overlay