CMS Side (Custom URL Tracking)

I have created a PHP CMS system for the project I am working on now which allows users to manage their profile page (profile.php?id=5, profile.php?id=12, ect…). In the CMS I have a analytics section where they can see how many visits their page gets in the last month via Piwik Widgets.

I have accomplished doing this successfully with Piwik, however, I’m not sure if I am doing it in the most efficient way and would really appreciate some guidance.

Currently my steps are:

  • Add the profile page to the database (/profile.php?id=20)
  • Add new site via SitesManager.addSite
  • Add the new User in the settings
  • Store the user’s token_auth in my site’s database to be used dynamically.
  • PHPMyAdmin to Piwik_site, and change the idsite to match the id in my site’s database (20 in this case) so I can pull it out dynamically for the analytics page.

So the outcome iframe would look like this (which gets pulled in to the CMS via ajax).

<div id="widgetIframe"><iframe width="380" height="850" src="<? echo DE_URL; ?>/piwik/index.php?module=Widgetize&action=iframe&columns[]=nb_visits&moduleToWidgetize=VisitsSummary&actionToWidgetize=getEvolutionGraph&idSite=<? echo $venID; ?>&period=week&date=last4&disableLink=1&token_auth=<? echo $_SESSION['ownerinfo']['token_auth']; ?>" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>

As you can see this is a pretty tedious process (especially changing the idsite to match the profile ID) to enable analytics to the CMS for a user. Any advice or ideas on how I could accomplish this in a more efficient way would be very appreciated. If I can maybe tweek the SitesManager.addSite action to add a custom ID number instead of the of it auto incrementing, that would be a huge help. Perhaps I will have to write my own script to query the piwik database?

Thanks!