Gemma Black
Gemma Black

Follow

Gemma Black

Follow

How to set up Pirsch Analytics in Nuxt 2

Gemma Black's photo
Gemma Black
ยทApr 14, 2023ยท

2 min read

How to set up Pirsch Analytics in Nuxt 2

You may have your reasons for searching out an alternative to Google Analytics. If you want to get set up with Pirsch Analytics and Nuxt 2, you'll find the process very quick.

Pre-requisites

  • You will need a Nuxt application hosted on a live domain name. It won't work locally.

Step 1. Getting set up with Pirsch

Sign up with Pirsch through https://pirsch.io/ and verify your email.

They'll take you through an onboarding process where you can add your domain name. Make sure to include www if that's where your naked domain redirects to.

They'll show you a Script tag that you can copy that looks like this:

<script defer type="text/javascript" src="https://api.pirsch.io/pirsch.js"
    id="pirschjs"
    data-code="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></script>

Step 2. Loading their script in Nuxt

With Nuxt, they use Vue Meta, the HTML Metadata manager for Vue.js. This allows you to inject scripts or stylesheets amongst other things into the header of your SPA, universal or static app.

Add the following script block through the nuxt.config.js .

export default {
  ...
  head: {
    script: [{
      src: 'https://api.pirsch.io/pirsch.js',
      'data-code': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      type: 'text/javascript',
      id: 'pirschjs',
      defer: true
    }],
   ...
}

Change the data-code to match the code from Pirsch.

Step 3. Deploy and wait

Within minutes of deploying, we had cookieless, privacy-first analytics. It took longer to write this article than it took to make the change and get set up with Pirsch ๐Ÿ˜‚.

Disclaimer: Why not Google Analytics?

Firstly, I just have to make sure I'm not mistaken; I have no hatred for Google or for Google Analytics. Yes, the mass data collection is a little creepy, but more importantly for me, I can't stomach the cookie (๐Ÿช) bombardment (๐Ÿ’ฃ) after GDPR came in. I don't want that experience for users at embodimentshop.com either.

ย 
Share this