setDocumentTitle not working?

I tried using _paq.push(['setDocumentTitle', "<?php echo $_SESSION['name']; ?>"]); To replace the title of the page with the username of the user but it keeps showing the <title> of the page. On the HTML Source its showing the correct name:
Here is all the code:
var _paq = _paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', '4']); _paq.push(['setDocumentTitle', "<?php echo $_SESSION['name']; ?>"]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })();

EDIT: Console doesn’t throw any error.

You need to set the document title before tracking the page view.

something like that :

_paq.push(['setDocumentTitle', "<?php echo $_SESSION['name']; ?>"]);

You did the inverse here !

1 Like

Hmm that worked perfectly.
I think that i copied that script from the Piwik wiki.
Thank you very much for the help!