Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5706

Need help setting up single page web application

$
0
0

@neunzehnachtneun wrote:

Hi all!
I am using Matomo to track a single page website. Following this guide I added this code into the head section. But unfortunately it doesn’t track new page views. Am I missing anything?

Thanks in advance!
Sebastian

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  _paq.push(['trackPageView']);
  
  //_paq.push(['enableLinkTracking']);
  (function() {
    var u="https://matomo.neunzehnachtneun.de/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', 1]);
    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);
  })();
  // Single Page Application Tracking
  var currentUrl = location.href;
  window.addEventListener('hashchange', function() {
      _paq.push(['setReferrerUrl', currentUrl]);
       currentUrl = '/' + window.location.hash.substr(1);
      _paq.push(['setCustomUrl', currentUrl]);
      _paq.push(['setDocumentTitle', 'My New Title']);

      // remove all previously assigned custom variables, requires Matomo (formerly Piwik) 3.0.2
      _paq.push(['deleteCustomVariables', 'page']); 
      _paq.push(['setGenerationTimeMs', 0]);
      _paq.push(['trackPageView']);

      // make Matomo aware of newly added content
      var content = document.getElementById('content');
      _paq.push(['FormAnalytics::scanForForms', content]);
      _paq.push(['enableLinkTracking']);
  });
</script>
<!-- End Matomo Code -->

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5706

Trending Articles