04.24.08

Parsing the Querystring for dynamic content (and images)

General | 2 Responses

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

Tags: , , , , ,

2 Responses to “Parsing the Querystring for dynamic content (and images)”  

  1. Gravatar Icon JaredB

    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. Gravatar Icon Dan Cameron

    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.


Add your comment below, or trackback from your own site.
Subscribe to these comments.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« Smash Bros. Brawl
» Background apps on the iPhone - SDK 4
Creative Commons License