I'm guessing the Referral metric in Google Analytics increments when the url has a ref in it (coming from a different site such as https://website.com?ref=facebook), but if the user clicks on a separate page and the ref param is dropped from the url, does that increment the Direct metric?
Just want to make sure users aren't being double counted since just yesterday the Referral and Direct metric were the same which was odd. If that is the case, is there a way to make sure they are not double counted?
Using ga4
gtag.js
export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;
export const pageview = (url) => {
window.gtag("config", GA_TRACKING_ID, {
page_path: url,
});
};
export const event = ({ action, category, label, value }) => {
window.gtag("event", action, {
event_category: category,
event_label: label,
value,
});
};
_app.tsx in NextJS app
const router = useRouter();
useEffect(() => {
const handleRouteChange = () => {
gtag.pageview(window.location.href);
};
router.events.on("routeChangeComplete", handleRouteChange);
router.events.on("hashChangeComplete", handleRouteChange);
return () => {
router.events.off("routeChangeComplete", handleRouteChange);
router.events.off("hashChangeComplete", handleRouteChange);
};
}, [router.events]);