How To Add a Custom Welcome Based on Referrer
I recently added a little snippet of PHP to Video Rambler to welcome people that were coming from StumbleUpon with a custom welcome. The website recently got Stumbled again and one of the people that gave the site a thumbs up stated:
I only gave it thumbs up bc I’m wondering how they put that stumbleupon welcome message at the top…only shows if you stumble it.
Here is how I did it. I check the $_SERVER[‘HTTP_REFERER’] to see if it is one of the referrers I want to give a special welcome to. If it is then I simply echo some css to add some padding to the top of the screen and print out the custom welcome. This might not be fool proof, since some browsers do not pass the referrer, or people could fake the referrer, but it works quite well for StumbleUpon. You could make this more complicated and display a different message for more than just Stumblers, but those were the only people I was interested in at this time. I have been using it for a month and considering how well the website has been doing with StumbleUpon I think I will keep using it for a little while.
<?php $allowed = Array('www.stumbleupon.com','stumbleupon.com'); $camefrom = array_change_key_case(parse_url($_SERVER['HTTP_REFERER'])); if (in_array($camefrom['host'],$allowed)) { echo '<style type="text/css">body { padding-top: 25px; } </style>'; echo '<div style="position: absolute; top: 0; left: 0px; width: 100%; padding: 3px 15px 3px 15px; background-color:#ffffe1;">Welcome Stumbler! Hope you enjoy the site and it would be great if you would give a nice <a href="javascript:document.location.href = \'http://www.stumbleupon.com/submit?url=\'+ document.URL +\'&title = \'+document.title.replace(/%20/g,\'+\');">Thumbs Up!</a> Enjoy!</div>'; } ?>
Comments
Social Media Future &raquo; Blog Archive &raquo; Make Your Site Stumbler Friendly
[...] and encourages them to subscribe to your feed. If you are not using WordPress, but you can run PHP consider adding a similar PHP script to welcome [...]
LGR Webmaster Blog - Make Your Site Stumbler Friendly
[...] can edit the message to say what ever you want. If you are not using WordPress, but you can run PHP consider adding a similar PHP script to welcome [...]
Mike Smith
I've been wondering how to do this and am going to add it to my blog now. Thank you for posting the code. I appreciate it.
Greet Visitors By Where They Came From : InternetBasedMoms Experts
[...] technical elbow grease. Ask your techie to help you with that. Technically inclined? Then check out this short tutorial and code [...]
Jennifer Brumble
For non WP users, here's another tutorial tapping into Google scripts, in face the whole script one adds is 11 lines long. http://www.quietaffiliate.com/dynamically-generate-users-location-on-landing-pages ----- in case their sites goes down, here's the code ----- if (typeof(google.loader.ClientLocation.address.city) != null) { document.write(google.loader.ClientLocation.address.city +", " +google.loader.ClientLocation.address.region); } else { document.write("Unknown location") }
LGR
Interesting post. I will have to give that a try.
Rob
Could you also write a Javascript version of the script? I haven't been able to find one anywhere.
LGR
You know I did have a Javascript version at one time. I'll see if I can find it and write a post about it. If you are using WordPress take a look at the WP Greet Box plugin. I have been happy with it on WordPress sites.
mark
So I wonder is there a way to make this work on blogger? <abbr><em>mark’s last blog post..<a href="http://unfortunatenames.blogspot.com/2009/05/unsanitary.html" rel="nofollow">Unsanitary</a></abbr></em>
LGR
I had another request that was similar. I have an idea, just need to get some time to put it together and test it. Stay tuned, maybe I will get some time this weekend. Cross my fingers.