-1

I have written a PHP based blog for the company i work for. Not using any frameworks. I am having trouble tracking users who come from my facebook page's posts to my blog (not wordpress).

I have created a shortlink url. Let's say it is sample.co and it redirects traffic to sample.com. Everything seems fine until here. The problem starts here.

I am adding all user's ip's, user agents. But if even i get 500 visits, my code adds somethig like 3.000 visits. Facebook stats and Analytics shows similar stats (~500 visits). I see that ip's added to MySQL are all different. It usually happens with Android users. I have read somewhere that Facebook sometimes renders to their users the actual URL when FB shows the post. I mean instead of the widget, Facebook shows the whole page. I am not quite sure about that to be honest.

To solve this problem, I have created and added an jquery script to my page and listened users' scroll event. It worked great. Not seeing too much traffic. But this time the problem is i am counting less users. Even I get 500 users from facebook and Analytics shows similar results, my script adds only 200-300 to MySQL.

Does anyone know a better way to track real traffic? Or do you aware of such problem?

Thanks

blacksun
  • 733
  • 7
  • 24

2 Answers2

0
  1. It should be filtered on the basis of user agent.

    https://developers.facebook.com/docs/sharing/webmasters/crawler

    how to detect search engine bots with php?

  2. Identifying users through IP is a good idea, but if your IP keeps changing, it's a good idea to use cookies.

    http://php.net/manual/en/function.uniqid.php

    If the cookie does not exist, you should see it as a new user.

Community
  • 1
  • 1
Ray
  • 767
  • 4
  • 11
  • I have already filtered on agent basis. It didn't work because even real users have same agent. They usually come via Facebook mobile app. And their Agent do not change. IPs do not change. I get same ip for same user. When i mean different ip, i mean different user. But they don't actually visit page. They just see the widget. – blacksun Feb 05 '17 at 08:02
  • To clear, they are not bots. They are users who see the "widget" facebook shows them. But most of the time, they look like they have actually visited the page. – blacksun Feb 05 '17 at 08:04
  • Interesting, how about cookie?https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id – Ray Feb 05 '17 at 08:23
  • I am tracking them using cookie. I don't need to identify them as a new user or not. I hust need to track real visitors. Sometimes they have cookie but it doesn't mean that they have clicked on the link. They have previous cookie. My problem is not tracking new users to be honest. My problem is counting traffic. When facebook shows our post to a user, it seems like they have clicked on the link and visited the page. This is not normal because they have just seen it not clicked on it. – blacksun Feb 05 '17 at 09:32
0

I have found the answer. The problem is called preview (prefetch). Here is the link:

https://www.facebook.com/business/help/1514372351922333

Simply, facebook preloads everything when FB shows the thumbnail to the visitor to speed up your page's load speed. They send X-Purpose: preview header. So you can simply check if HTTP_X_PURPOSE header's value is preview or not. If so, do not count it as a visitor.!

Here are more detailed descriptions:

http://inchoo.net/dev-talk/mitigating-facebook-x-fb-http-engine-liger/

http://inchoo.net/dev-talk/magento-website-hammering-facebook-liger/

blacksun
  • 733
  • 7
  • 24