This code was created to help count the number of times a like or tweet or share button was clicked on a particular page.
- Signup for a developer account on Facebook. Create an app, and grab that App ID.
- Add that App ID to two pages:
social.js
andindex.php
- Change the domain listed in
social.js
to your domain - It needs to point to yourchannel.php
- Make sure that the page that has the social buttons on it has all the meta information filled out. This is where the buttons get their data from.
socialcounter.php
needs to have a MySQL connection. So include your connection file, or connect to MySQL at the top.- When
socialcounter.php
saves the data to the database, it assumes the schema that is listed instats.sql
- Ensure that
social.js
is pointing to the correct place when it is looking forsocialcounter.php
- At the top of
index.php
, there is a PHP $_SESSION variable. This should be a unique value for whatever page is being shown. (This assumes that you have multiple pages you want to track actions on separately.)
Note: I've documented each step within the code. There are a lot of links to resources within the code. Hopefully this saves someone from having the same trouble I did finding the stuff...