Hey guys I’m going to talk about stopping the traffic coming to your website, actually you want to get traffic but sure you don’t want referral traffic from bad websites.If your analytics properties are showing a huge amount of traffic from referral sites they you might think about it once. If you are monetizing with adsense then your 50% of the traffic should be organic which is coming from the any search engine.Let’s talk about why bad websites send traffic and how they harm you, finally how to stop them.
Why bad sites send traffic?
Obviously they want to harm you , your site and your great work. If the website owner is using your theme then may be he has added a credit link to your site. some spammers do send traffic with a referral url which usualy redirects to affiliate page of other websites.The only thing you will lose is your adsense account for getting low quality traffic and more traffic will slow down your website too.
Why you should stop traffic from bad sites ?
Yes you love more traffic coming to your site , but this type of traffic is low quality in eye of google. If your are using adsense. The adsense requires 50% of the traffic from organic search else your account may get disabled. Most of any good advertising networks do not like this type of low quality traffic. so better you stop this kinda traffic and be safe from adsense.
You can check the referral traffic in your analytics by going to google analytics >> Traffic sources >> referrals.
How to stop any site from referring ?
You just need to add a simple javascript code or PHP code whichever you are good at.
Change the url1,url2 from which you want to block the traffic.
Change the GOTO with the url you want to redirect.
And add the code inside head tag.
Javascript code
var blocklink = ['url1', 'url2'];
for (var b = blocklink.length; b--;) {
if (document.referrer.match(blocklink[b]))
window.location = "http://GOTO/";
}
PHP code
$blocklink = ['url1', 'url2'];
foreach ($blocklink as $value) {
if ($_SERVER['HTTP_REFERRER'] == $value)
header('Location: http://GOTO/');
}
You can also stop spam referrals using .htaccess file, see How to do it with .htaccess file
If the code doesn’t work and then you can just filter them in analytics.
Filter spam traffic with analytics filters.
Share this article. For any help comment below.
5 Comments
name
Really appreciate you sharing this blog.Much thanks again. Much obliged.
Bisnis Online
thanks so much brother your posting, i want to make a block from forum topic darodar, i dont know where is from the visitor
crorkz linkz
I’ve recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time and work.
Jeff
So I figured out the reason that people were saying the PHP code wasn’t working. There’s actually a few reasons:
A) It should be HTTP_REFERER, not HTTP_REFERRER – there’s two many “R’s” in the php code above.
B) It throws an indexing error if you go directly to the link (which isn’t really an issue since this is coming from ‘referral’ spam which by it’s very nature should populate the HTTP_REFERER global variable). So speaking more from a user side than stopping spam, if you don’t make sure the HTTP_REFERER variable is set using something like “if (isset($SERVER[‘HTTP_REFERER’])”, PHP will throw an indexing error.
C) As a side note, the php method itself is only semi successful in blocking referrer spam. The reason is the HTTP_REFERER variable itself can be manipulated by the end user. So any hacker worth their code could easily make this a randomly ‘referred’ site as a work around – which means you’d have to stay on top of your analytics to see where the referral spam is coming from.
Chris
If you want to block the traffic from showing in your analytics then you need to stop the spam using .htaccess file. Putting the .php or java script into the header will not prevent this.