If you website use google analytics with “ga” object in page, you can use the following snippet to send custom page viewed.

It can be useful to track certain actions, such as a form submitted with success, or whateaver is not a phisical page.

In this case we would like to send the page “/pippo/pluto” viewed

const tracker = window.ga == null ? null : window.ga.getAll()[0];
if (tracker && tracker.set && tracker.send) {
  tracker.set('page', '/pippo/pluto');
  tracker.send('pageview');
}

More info: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages

Categories: Js,Ts,Css

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.