Problem - Setting Custom Variables and Tracking Them


#1

Hi,
First, sorry if I am duplicating any existing post about this topic. But I already searched forum but couldn’t find any related answer. May be I am overlooking.

My problem is, I am successfully can set the custom variables but unable to track them and getting results in Piwik admin. Here is my Piwik javascript implementation code.


var _paq = _paq || [];
(function() {
  var u=(("https:" == document.location.protocol) ? "https" : "http") + "://[piwikurl]/";
  _paq.push(['setSiteId', 1]);
  _paq.push(['setTrackerUrl', u+'piwik.php']);

  _paq.push(['setCustomVariable', 1, 'VisitorType', '<?php echo isMember() ? 'Member' : 'Non-Member';?>', 'visit']);
  _paq.push(['setCustomVariable', 2, 'RoleType', '<?php echo roleType();?>', 'visit']);
  _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);

  var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
  g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

As I already mentioned that I can see these custom variables under “Visitors -> Visitors Log”. But when I go to “Visitors -> Custom Variables”, there is no tracking data against the custom variables.

I am not sure the problem is in the following code or somewhere else:


_paq.push(['setCustomVariable', 1, 'VisitorType', '<?php echo isMember() ? 'Member' : 'Non-Member';?>', 'visit']);
_paq.push(['setCustomVariable', 2, 'RoleType', '<?php echo roleType();?>', 'visit']);
_paq.push(['trackPageView']);

Here are my results from Piwik admin: http://content.screencast.com/users/haroon.allshore/folders/Jing/media/c1ab063b-4ce7-47be-8944-cfe36301f04c/2014-05-19_1956.png

Do I need to make any changes in Piwik settings? Do I need to call “trackPageView” after setting each custom variable.

PS: I am using Piwik 2.2.2.


(Matthieu Aubry) #2

If you see the custom variables in visitor log they should definitely appear in the Report as well. Sorry here I have no idea what may happen. Maybe try to view stats for only one day, does it work? Also, maybe try to setup the cron as explained in How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo


#3

Oh, thank you sooo much Matt. It helped and I am now able the see the stats by setting option to auto archiving.
I don’t know how make the answer a solution or topic to solved.
But Answer is the Solutions and Topic status is Resolved now.
Thanks again! :slight_smile: