Loading...

Parsing the Querystring for dynamic content (and images)

Thanks to Nathan I was able to implement some javascript that would dynamically replace some eye-anchors through a query string in the URL on my company’s website.

We’ve been wanting to create some value propositions to our prospects on different marketing channels for a while now but until we get Omniture’s Test and Target we’ll have to settle for this little trick.

For our tests we’re going to take our normal landing pages and present different creative to our major channel, pay-per-click. Making sure we keep this test meaningful we’re keeping the old add copy and landing page but splitting the ad campaign, essentially making it a multi-variant test by splitting traffic to the same page with different query strings.

On to the technical side of things:

  • Download Adam’s JS here
  • Upload the code to your server and reference it in the header of your pages like so,
<script src=“http://dancameron.org/qs.js”></script></head>
  • Create your script and objects. Below is what I use to swap out the image.
<script>

/* Query String Script ask DanC to modify or use */

var qs = new Querystring();

var img=qs.get(’img’,'http://dancameron.org/default.jpg’);

var title=qs.get(’title’,'default tile’);

var url=qs.get(’url’,'default.url’);

var alt=qs.get(’alt’,'default.alt’);

document.write(’<a href=”‘+url+’”><img src=”‘+img+’” border=”0″  alt=”‘+alt+’” title=”‘+title+’”></a>’);

</script>
  • Then I just add the strings to the URLs like,

http://test.com?img=http://dancameron.org/mytestimage.jpg&alt=blah&title=blah&url=http://google.com

2 Comments

  1. Posted April 25, 2008 at 8:24 am | Permalink

    I’m assuming that you’re not worried about people who have Javascript disabled, right?

    Also, I can’t remember the details right now, but I know I’ve seen a lot of standards people poo-pooing document.write and favoring standard DOM methods instead.

  2. Posted April 25, 2008 at 12:41 pm | Permalink

    Out of 136K visitors in the last week we had a total of 4 with js disabled.

    And I’m not worried about standards on this site, it’s a train-wreck already.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*