Skip to content

Commit

Permalink
[core] Finish migration to GA4
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 1, 2023
1 parent ba42c92 commit d7c6725
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ MyApp.getInitialProps = async ({ ctx, Component }) => {
// Track fraction of actual events to prevent exceeding event quota.
// Filter sessions instead of individual events so that we can track multiple metrics per device.
const disableWebVitalsReporting = Math.random() > 0.0001;
export function reportWebVitals({ id, name, label, value }) {
export function reportWebVitals({ id, name, label, delta, value }) {
if (disableWebVitalsReporting) {
return;
}

window.ga('send', 'event', {
eventCategory: label === 'web-vital' ? 'Web Vitals' : 'Next.js custom metric',
eventAction: name,
eventValue: Math.round(name === 'CLS' ? value * 1000 : value), // values must be integers
eventLabel: id, // id unique to current page load
nonInteraction: true, // avoids affecting bounce rate.
window.gtag('event', name, {
value: delta,
metric_label: label === 'web-vital' ? 'Web Vitals' : 'Next.js custom metric',
metric_value: value,
metric_delta: delta,
metric_id: id, // id unique to current page load
});
}

0 comments on commit d7c6725

Please sign in to comment.