SyntaxError: expected expression, got '<'



I’m new to Matomo so this may be an easy fix that I have just overlooked. Initially I installed Matomo on a Ubuntu hyper-v on my local laptop and everything installed fine. I setup the website tracking, copied the javascript to the site I wanted to track and things worked as expected. Next I installed Matomo on a Windows server running IIS. Since there are other sites on this server I set it up on a different port. I setup the site I wanted to track (which is the same site I was tracking earlier) and now when I load the site in Firefox and Chrome I get an error: SyntaxError: expected expression, got ‘<’ and nothing is tracked. Is there a setting or something else that I need to check in order to get this to work?


(Lukas Winkler) #2


The error message means that you copied the tracking code somewhere where it isn’t valid.

Most likely you copied the <script> inside an existing <script>.

E.g. like this


// some existing JavaScript

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  (function() {
    var u="//{$PIWIK_URL}/";
    _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.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
<!-- End Matomo Code -->


which is invalid HTML.

So make sure your tracking code is valid.