Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

Php track visits info via piwik (possibly via api or php piwik interface)

Id like to track views to a set of pages i have, and make a report of them. Im having trouble as there are so many ways in piwik to do this. there is an api to return info via xml or json etc. this works well to get page information as i have piwik all ready setup. i also noticed theres a way to make custom values in php via a php tracker.

So how do i implement this:
i have a page set of /single_event_page.php?id=64 where the id= is the event id of my mysql record.


this works very well, but im trying to capture multi event listings page views and save them daily and a total for the month in my database

i was thinking of doing this in a  cron job at 3:30 am as that california is 3 hours off from us so all of usa hits are properly counted.
and setting up a database table Daily_Views with fields of  PAGE_ID, DATE_STAMP,UNIQUE_VIEWS, PAGE_VIEWS
and repeating for Month_Views but having DATE_STAMP being MONTH as the field

this way i can then print my report by page ID getting my event info in a joined table lookup.

so would i capture all the json data and collate to save it to mysql or is there a better way it seams with a large site of 1000's of events this would take a very long time. as id be doing on the first of each month both the prev months totals and the daily totals for that day too making all this lookup take a super long time.

if i do custom values in piwik can i just print a report with all my pages maybe and have piwik do the processing? and not have to save the info to mysql. or even make a php file that uses the api to just display my block of event pages.

some notes:
each event has an author i need to block the event page views for each page for each author ie:
John has events with id's 1,3,7
Jane has events with id's 2,4,5,6

im asking this as its very complicated to me and im not sure the best way to handle my reports of pages.

heres piwiks info as reference

thank you in advance for any code or help you may provide
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

The mainstream tool for this sort of thing is Google Analytics and Piwik is wa-a-a-y out of the mainstream.  Google has already answered most of the questions about analytics with built-in functionality that is widely accepted as the industry standard.  If Google Analytics cannot meet your requirements, there is a Piwik forum where questions and answers are more directly focused on Piwik.

And, of course, there is the obligatory Professional Services Team.  These teams seem to show up with every open-source project.  I wonder if they make a lot of money?

Data bases where the row numbers are counted in the thousands are considered "tiny" by today's standards, so you would not expect to see any performance issues from something like that.  This article has some SQL performance guidelines that are applicable to any data base, so if you're concerned about performance, keep these in mind.
Avatar of Johnny


@ Ray Paseur™ always good to see you field a post. i have used google analytics before a while ago, and google analytics didnt have half the features piwik has. as i said its been awhile so it may have changed. i do like most google products.

i have no way of knowing the scope of the hits that will come to the site, but im talking 1k's a DAY or a better word would be a very heavy visited site. multiple times just for the page alone with one user alone its an event driven site and it will be world wide. again no idea of how many but im expecting it to be use a lot.
with that said, i picked piwik as i like it and have used it for many years and i have not used any of the api features. it seems to do what i need but i am unsure how to use it.

my second question in this post is is it a good way to capture json data for each page(as there maybe thousands for that too) info and process it. i can see this being very slow, and seams to not be efficient at all.

i thought of just making a ip views counter and hits tally for each page, and running my reports from them. but theres still isp's out there sharing ip's. so i thought ok there cookies or sessions, and said well piwik does this and counts it for me why cant i use its info. instead of reinventing the wheel, then i ran into how do i do this the right way. hence the post.

sorry you dont like piwik, and favor GA(not saying it's bad again have not looked at it in several years).

im open to other ways to do this but a global answer is not what im looking for, i dont mind researching farther but i need at least a direction. and outline of how to handle this.
pasific to my needs not use GA and speed up your mysql. im looking for with ga you can do blah blah..

thanks again for your reply you always do an angel id never of thought of and im happy for the mysql link too, something i would not of again thought of.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny


ok heres what i came up with: for now..ill revisit this later as it seems to be much more envolved then i thought and its going to require much more research.

 Views: page has a uniquie page view (first time viewed)
 Hits: Page has a tally of all views recuring and first time viewed
 loged in user: registered and we have there info on file
 blind ip: we have no record of users ip or is NOT loged in
 check if user is logged in
       if logged in see if user is in database as a view to the page. if they have not add to database as
             user_id,ip,mobile(android/apple/etc)or pc,page,time/date stamp,flag first view
       if user has visited page before add record but change flag first view to recurring flag
 if not logged in user then ad ip as user with blind note as user id of 0 (as there is no 0)
 tally days totals for any date and month of ie january 2014, by searching time/date field. hits will be tally of first view and recurring.
 views(unique) will be with first view flag only

i understand ips can be shared and i also understand its not the best way but it will get me up and running and have at least a min count correct. for hits and unique visits.

@ Ray Paseur™ your nifty explanations always floor me. i seriously wish i knew a fraction of anything you know, i struggle some times. and have to research a lot. thank you for clearing up the json matter and mysql matter of heavy hits to the pages. i will look deeper into GA and piwik(docs are very global) and see if i can find a ga example or guide for all this..and see if i can refine my views/hits better. down the road, i added this ot the to-do lists.

im going to accept your comment because it answered my question of the BEST way to handle it, ill refine my question after i research some more if i need too.

thank you as always
Thanks for the points and thanks for using EE, ~Ray