Quantcast
Viewing all articles
Browse latest Browse all 4243

Javascript tracking code template (no replies)

Hello,

I have just updated piwik to the latest version and now because of the new helpful tracking code page I am unable to have a default tracking code template with the exact custom variables and php calls I need for my website. Is there any way of editing the file jsTrackingGenerator.js so that I can put in my variables in so far I have been able to put in half of my code which looks like the below by putting a \n\ at the end of each line but as soon as I get to the more complex parts of the custom variables with multiple quote marks in them the script fails as you would expect.

<!-- piwik Code --> 

<?php 
$user =& JFactory::getUser(); 
$uname=$user->name;
$email=$user->email;
$email = str_replace("@", "&#64;", $email);
$doc =& JFactory::getDocument();
$pagename=$doc->getTitle();
?> 

<script type="text/javascript"> 
  var _paq = _paq || [];
  piwikTracker.setCustomVariable(2, 'Name', '<?php if ($uname == null) 
{ echo "Guest"; } else { echo $uname; }?>', 'visit');
piwikTracker.setCustomVariable(3, 'E-mail', '<?php if ($email == null) 
{ echo "Guest"; } else { echo $email; }?>', 'visit');
piwikTracker.setDocumentTitle('<?php echo $pagename; ?>');
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://{$piwikUrl}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$idSite}]);
    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);
  })();

</script>

Viewing all articles
Browse latest Browse all 4243