Track Pageviews

Pageviews are used to track what pages a visitor is browsing across your site. A visitor can visit any number of pages during a browsing session, and these will be automatically tracked using the JavaScript tracker so long as it is installed on every page.

Parameters

The page URL and page title can be modified. Other parameters (such as user-agent, screen dimension etc.) are all detected internally when the pageview is tracked.

NameDescriptionTypeDefault
URLThe URL of the page to track. This will be resolved relative to the current URL.Stringwindow.location.href
TitleThe title of the page to track.Stringdocument.title

Usage

<script>
  !function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
  arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
  d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
  insertBefore(d,q)}(window,document,'script','_gs');

  // false here tells the tracker not to
  // automatically track a pageview
  _gs('your-project-token', false);


  // do some stuff, for example loading an AJAX web app
  // using 'setTimeout' to mimic the delay in loading external scripts
  setTimeout(function() {
    // our app has loaded, lets track a pageview now!
    _gs('track');
  }, 1000);


  _gs('track');
  _gs('track', '/custom-path', 'Custom title');
  _gs('track', 'http://customdomain.com/custom-path', 'Custom domain + path');
</script>