Intrigued by this idea, I set off to find something similar for Blogger (a.k.a. Blogspot) based sites. After a lot of searching, I failed to find anything. I figured it couldn't be too hard; I'd just roll my own. It took a bit more work than I expected, but I finally came up with my own variation. There is no code shared at all with the WordPress plug-in; it's simply similar functionality inspired by Seth's observation and Richard's implementation. The following explains how to configure a Blogger site display different text based on a user's visit count.
I'm no copywriter and obviously you'll want different text, but the important thing is to have two div sections with IDs of NewVisitor and ReturningVisitor, and with a style attribute for both set to display: none;. When the page is loaded, one section or the other will be changed to visible based on the result of a cookie.
<div id="NewVisitor" style="display: none;">Thanks for visiting! Use the RSS feed or e-mail subscription to keep up to date on what's happening on this site.</div>
<div id="ReturningVisitor" style="display: none;">Welcome back! We're glad you enjoy our writing. If you especially like a particular article, please consider casting a Digg vote. Thanks!</div>
Except for the limitations of ID and style, the rest is normal HTML. You can put things that are common to both text sections outside the div sections. Inside the div sections, put things you want displayed for the context identified by the ID attribute.
Save the gadget. Since the text is inside a gadget, you can move it to where you want it to display.
Next, select the code below and copy it to the clipboard. Then go to the Edit HTML section of your blog configuration and scroll down through the template code until you find the line that says <body>. Just above this line, there will be one that says </head>; paste the copied code just above the </head> line.
<!-- Start of script for "WWSGD" div manipulation -->
if (document.cookie.length > 0)
c_start=document.cookie.indexOf(c_name + "=");
if (c_start != -1)
c_start=c_start + c_name.length+1;
if (c_end==-1) c_end=document.cookie.length;
var exdate=new Date();
document.cookie=c_name+ "=" +escape(value)+
: "; expires="+exdate.toGMTString()+
if (wwsgd_count == null || wwsgd_count == "")
wwsgd_count = 0;
wwsgd_count = parseInt(wwsgd_count);
visibleTag = 'ReturningVisitor';
<!-- This will show the "new visitor" text three times.
Change 3 to the desired value. -->
if (wwsgd_count < 3)
visibleTag = 'NewVisitor';
divToSee = document.getElementById(visibleTag);
if (divToSee != null)
divToSee.style.display = "block";
<!-- End of script for "WWSGD" div manipulation -->
Finally, on the <body> line, before the closing ">", add onLoad='checkCookie()'. When done, this line will look like:
When these three things are finished, the site should show the items inside the NewVisitor div section the first three times it is visited. After that, the items inside the ReturningVisitor should be displayed. If you want a different count for the first message, change the numeral 3 in the script (indicated by a comment) to the desired number. If cookies aren't enabled, then nothing will be displayed.
Leave a comment if you have any thoughts or find this useful. Thanks!
ResourcesThanks to the following for information found useful in the development of this tool:
- W3 Schools: a great reference on web technologies from AJAX to XSLT.
- ProBlogger: a must read for anyone serious about their blogging.
- Richard Miller: the original source of coding inspiration for this.
- Seth Godin: marketing thought leader.
- Mike Fitzsimon: for showing how to display code in a blog post well.