Need suggestions about a Facebook analytics system - php

I'm working on a small project which will basically do some Facebook stuff and pulls the new daily like for client's pages into my database so I could show them my own charts with their page statistics. Now first of all, I have made a cURL request running with a cron-job and scraping their Total Likes every day using the simple graph-api URL.
The problem is with New Daily Likes / Daily unlikes because, based on my little research, there is no way to access these without having a valid access_token and doing today total - yesterday total is not exactly correct, because it will confuse the new likes with the people who disliked this and it will be a total mess.
I don't want to force my clients to go to Facebook and get an access token to access the insights for 2 reasons: 1) I want it to be totally non-technical so they will not need to mess too much with tokens and stuff outside of my panel. 2) I bet some of them will have problems with storing their access tokens in my database.
How do I do that so they will only need to give me the ID of their page (that's how it currently works and I don't want to change it)?

Basically, there are 2 ways to get Likes information, one is to query public information, like:
http://graph.facebook.com/cocacola
And the other one is to query for page insights information, for which you need access tokens with right permissions.
If you don't want your clients to install your Facebook application with permissions (and with that, give you access token), your only option is to query public information.
As you've noticed, that gives you a problem, since each day "likes" gain is "mashed up" from users adding likes and removing likes, and thus, you dont have precise information about how many users liked and disliked every day. One way would be to query the information, lets say per hour, or even 5 minutes, and store that information. Then, by simple math, you can see how many users liked and disliked the page. It is still not totaly precise, but its alot more valid than "daily information".

Related

Best way to save user view counts for advertisements in PHP & REST API

I have a REST API built with PHP & MySQL for storing ads.
My database contains an ads table and a users table.
I want to bump the view count for every ad once a user is viewing it (only once, if he views it for the 2nd time, I don't want to raise the count again).
Also, how do I go about setting up a service for the client? Psychologically it seems very aggressive to make a server request each time a user is watching an ad, it could get to hundreds of requests at the same time.
Thanks! :)

PHP How to track user's navigation path through a website

So we plan to track a user's activity within our website which are in PHP.
What we want to know is track a unique session for a user from the time he first visits a page in our site, the pages he visited next, and visited last.
Some kind of tracking his footprint through our site.
We actually have identified 2 methods, one is using a custom code, and the other is analytics.js.
We find analytics.js too much for this (and my take more time to setup including time for our Internal Team to familiarize/learn the tool).
Considering what we need is just getting the timelogs of the user's session.
So we'll be going with a custom code added to each of the pages that need tracking. This script will do the follow:
we will be pasting code snippets to pages that need tracking
generate a unique session ID once he lands on any of the tracked pages
records the activity on a database
create an admin dashboard to visualize each of the user's activity, just a simple UI to showing the timelogs and pages visited
That's our plan so just wondering if the above is acceptable, or if there's any other easier way to do it?
Thanks in advance StackOverflow community!

No of page likes for a facebook page for particular daterange

I am trying to find no of page likes for different pages in a date range. I tried different method like page_fans_country/lifetime to know but i don't think that's correct api call to get this information.
Right now i am able to know the likes of page at present but i like to know likes for a page in past 15 days.
$app_result = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=[APP_ID]&client_secret=[APP_SECRET]&grant_type=client_credentials');
$access_token = trim(str_replace("access_token=","",$app_result));
$result = file_get_contents('https://graph.facebook.com/'.$fb_page_link.'?access_token='.$access_token);
$data = json_decode($result,true);
Can any one point me in right direction to get this information.
Try this:
https://graph.facebook.com/[PAGE_ID]/insights/page_fans?since=[2014-01-01]&until=[2014-02-01]&access_token=[ACCESS_TOKEN]
The only limitation is the daterange cannot be bigger than 35 days.
As far as I know the page_fans metric is only available to page owners or people with the respective privileges. So it's not working to get the insights from any page, but only for those which you administer.
https://graph.facebook.com/{page_id}/insights/page_fans?since=2014-06-15&until=2014-07-14&period=period(%27day%27)&access_token={page_or_user_access_token}
If you own the page, you can use the read_insights permission to grant the access right to the data, see https://developers.facebook.com/docs/graph-api/reference/v2.0/insights/#reading
If you're not the owner of the pages, the only chance you have is to recurrently read the likesdata from the individual page object (https://developers.facebook.com/docs/graph-api/reference/v2.0/page#readfields) on a daily basis to generate the stats by yourself:
/{page_id}?fields=id,likes
The gathering of historical data is not possible with this method.

Facebook page post share count per user

I'm trying to recreate a Facebook page tab application similar to this one: https://www.facebook.com/andrewchristian/app_118098318208381
Up to now, using FQL, I plan on fetching user data (if the user liked/commented on a post) and display a list with an order based on their activity. It will be a cron running once or twice a day. The only thing I'm missing is a way to know if the user has shared any of the page's posts.
I've been digging around in the FQL tables (the link is for the stream table) for any clues but I cannot find anything to work with. Has anyone done something similar? Any other ideas on how I can fetch such information? This has to work as "per user", I'm not not interested in the total count of shares on a post.
P.S.: If there is something that counts a user's total likes/comments/shares on a Facebook Page, I'd really like to know about that as it would make my life much easier, I'm open to any suggestion!
Thanks in advance!

Facebook keeps deleting my application

FB keeps deleting my application. I am thinking that the likely problem is that we allow users to share their score result with their friends, i.e. the user can select group of people who are also in the same group, and the script will post on all of their walls. I don't think that app is acting in any way not in accordance with FB policy. My guess instead is that due to relatively high amounts of requests to post feed [some users can select 100 and more friends]. Can it be so? Is there a way to post multiple feeds in single request, in that case?
http://developers.facebook.com/docs/guides/policy/policy_checklist/
Ensure that the application "does not provide users with the option to publish more than one Stream story at a time."
The behavior that Facebook wants you to use is that a user posts something on his own profile to share it with multiple people. Posting the same story on multiple profiles at once is contrary to how the social channels are meant to be used.

Categories