If you haven't already, please read the Google Analytics Integration Overview guide and link your Persosa account to Google Analytics.

NOTE: The gtag.js integration is currently in Beta. Please contact us if you notice any issues.

Update config initialization

gtag.js requires you to initialize custom dimensions when initializing the gtag object on your site. Right now, this probably looks something like this:

gtag('config', 'UA-XXXXXXXX-X');

NOTE: Ensure that the Persosa tracking snippet is loaded on the page before initializing gtag.js

We'll need to update this line to tell gtag where to pass Persosa's experience data. You can see the exact configuration parameters on the Persosa integrations page for the Google Analytics integration. This will use the data from the custom dimensions that were created when you linked the two accounts:

So now, our new config call should look like this:

gtag('config', 'UA-XXXXXXXX-1', {
  custom_map: {
    'dimension3': 'persosa_id',
    'dimension2': 'persosa_name'
  }
});

Track Persosa Experience

Now that the config is updated, we need to tell Persosa to pass its experience data into Google Analytics. Place the following line after the initialization: 

persosa('ga', 'gtag'); 

Your complete gtag code should now look something like this:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXXX-1', {
    custom_map: {
      'dimension3': 'persosa_id',
      'dimension2': 'persosa_name'
    }
  });

  persosa('ga', 'gtag');
</script>

What does this code do?

After ensuring that Persosa is linked to your Google Analytics account and checking for the existence of the gtag() function on the page, the tracking code will fire off a non-interaction Google Analytics "Experience" event in the "Persosa" category, passing the custom dimension values with it in the persosa_id  and persosa_name properties accordingly.

The actual event looks like this:

gtag('event', 'Experience', {
  event_category: 'Persosa',
  event_label: '<Persosa Experience Name>',
  persosa_id: '<Persosa Experience ID>',
  persosa_name: '<Persosa Experience Name>',
  non_interaction: true
});
Did this answer your question?