Google Analytics

Integrating LogRocket with Google Analytics

Add a LogRocket session URL to Google Analytics as a custom variable. Add this code anywhere in your app, after LogRocket and Google Analytics have been loaded.

LogRocket.getSessionURL(function (sessionURL) {
  if (typeof gtag === 'function') { //Check if gtag is loaded
    gtag('event', 'logrocket', {
      'session_url': sessionURL
    });
  }
});

If you are deploying LogRocket via Google Tag Manager, you will need to wrap the code with <script> and place it in a Custom HTML Tag. This should be fired on All Pages. Make sure to fire the tag after LogRocket has loaded.

<script>
LogRocket.getSessionURL(function (sessionURL) {
  if (typeof gtag === 'function') { //Check if gtag is loaded
    gtag('event', 'logrocket', {
      'session_url': sessionURL
    });
  }
});
</script>

The code below is for Google Analytics UA, which has been sunset.

LogRocket.getSessionURL(function (sessionURL) {
  ga('send', {
    hitType: 'event',
    eventCategory: 'LogRocket',
    eventAction: sessionURL,
  });
});