xwp / site-performance-tracker

Allows you to detect and track site performance metrics
GNU General Public License v2.0
96 stars 15 forks source link

Don't send an extra page view #55

Closed dero closed 2 years ago

dero commented 2 years ago

Fixes #46

Tasks

Describe the Approach

If this plugin is supposed to enhance the existing Analytics setup, we need to not send a page view when we call gtag( 'config', ... ).

The standard gtag implementation would instruct web administrators to paste the following snippet to the <head> of the site:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'XXX');
</script>

The config call also by default sends a pageview.

This means when we make "our" config call later in the page lifecycle, we need to instruct gtag to not send a page view. That's what this PR does.

Note: Ultimately I wonder if there is a better way for us to apply "our" configuration. Maybe by using gtag( 'set' method or even altering the underlying dataLayer variable?