6

I am currently facing an issue need help . I am creating some URLs to my content on my website . Users of site can post them on their groups, pages on Facebook . I want to count clicks on those posts . I tried with a php function but the count from that function and fb insights (people reached) is very different.(fb insight showing 3 times less thn my data count) Why is that count is different? and if i want fb people reach data how can i get that as the page where user will post is not mine.

Regards

nOmi
  • 297
  • 3
  • 22
  • Clicks can be counted differently based on several things. First, make sure you're checking the referrer when counting clicks. Also, they may be only looking at unique users, which you can check by setting a cookie on the first visit, and not counting the click if cookies exist. This still may not match since they may be counting it by user and not by device, but it could get you closer to their number. – aynber Nov 04 '16 at 14:50
  • @aynber i am already checking the referrer on saving click data. instead of saving cookies i am checking user's ip for saving unique clicks only but still number of clicks differ too much . – nOmi Nov 04 '16 at 15:32
  • can you share your code? – Archish Nov 14 '16 at 10:53

1 Answers1

6

One possible approach is implementing your own algorithm based on the referrer, but there are some cases these you have to take in account. On a first thought here are some of them.

  1. How to determine unique clicks? (IP, Browser data or combination of both?)
  2. Is the referrer unique? (https://www.facebook.com/, https://m.facebook.com/)

I'm sure that there are other pitfalls too.

However you can try some tracking URL library, for example Google Analytics (for advanced statistics) or Google Short URL for a basic ones.

It's already answered on Stack Overflow, how to get page view information for specific URLs in Google Analytics.

Here is how Google Shorten URL works (the examples are taken by Google Shorten URL Docs):

For your URL you generate a shorten one:

curl https://www.googleapis.com/urlshortener/v1/url \
  -H 'Content-Type: application/json' \
  -d '{"longUrl": "http://www.google.com/"}'

If generation is successful, you will receive the following response:

{
 "kind": "urlshortener#url",
 "id": "http://shortenurl/",
 "longUrl": "http://www.google.com/"
}

Please note that id key is your shorten URL. So you can store it in your Database.

Later you can get your shorten URL statistics by the following call:

curl 'https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://shortenurl/fbsS&projection=FULL'

And here are the stats:

{
 "kind": "urlshortener#url",
 "id": "http://shortenurl/",
 "longUrl": "http://www.google.com/",
 "status": "OK",
 "created": "2009-12-13T07:22:55.000+00:00",
 "analytics": {
  "allTime": {
   "shortUrlClicks": "3227",
   "longUrlClicks": "9358",
   "referrers": [ { "count": "2160", "id": "Unknown/empty" } /* , ... */ ],
   "countries": [ { "count": "1022", "id": "US" } /* , ... */ ],
   "browsers": [ { "count": "1025", "id": "Firefox" } /* , ... */ ],
   "platforms": [ { "count": "2278", "id": "Windows" } /* , ... */ ]
  },
  "month": { /* ... */ },
  "week": { /* ... */ },
  "day": { /* ... */ },
  "twoHours": { /* ... */ }
 }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Jordan Enev
  • 16,904
  • 3
  • 42
  • 67
  • I am using just the ip to check uniqueness and using both the referrer for check like **if($_SERVER['HTTP_REFERER']=="https://www.facebook.com/" || $_SERVER['HTTP_REFERER']=="https://m.facebook.com/" || $_SERVER['HTTP_REFERER']=="http://m.facebook.com/")** i will check google short url an d come back with results. – nOmi Nov 13 '16 at 04:41
  • 1
    Keep in mind that Google Shorten URL will provide you with basic statistics. If you want advanced data - you can try with Google Analytics. They also have [PHP API Client](https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php). By the way Analytics has web interface and there you can make your referrer reports. However you can reach their [reporting APIs](https://developers.google.com/analytics/devguides/reporting/). – Jordan Enev Nov 13 '16 at 11:49
  • 1
    I've updated my answer and it includes reference to how to get page view information for specific URLs in Google Analytics. – Jordan Enev Nov 13 '16 at 12:10
  • i tried the google short urls but the result is same like it differs too much . fb shows say 20 clicks and and google short url shows 60 clicks – nOmi Nov 14 '16 at 07:10
  • You can try with Analytics. Just include their tracking script on all of your pages and you can check results in their web interface. If the results suits you, then you can integrate Analytics on the back end via their API. – Jordan Enev Nov 14 '16 at 07:24
  • Hey @nOmi do you try with Analytics? It's pretty simple and with their web interface you can easily validate the results – Jordan Enev Nov 15 '16 at 21:37
  • i have tested that already even before google short url. it tells different story as well . – nOmi Nov 17 '16 at 04:30
  • For sure Analytics will provide you with accurate data. Comparing two different metrics, i.e. `Facebook reach` / `URL unique clicks` will always differ in the result. Do you check Facebook Graph API? An [Object Insight API](https://developers.facebook.com/docs/graph-api/reference/v2.8/insights) might be helpful. – Jordan Enev Nov 17 '16 at 22:33