I try to update my Google Analytics implementation from analytics.js to the new gtag.js.
In the old implementation I am using the ready callback function.
ga(function() {
console.log('Google analytics is ready');
});
How can I implement a ready callback in the new gtag.js? I can't find any information in Google's documentation.
Unlike analytics. js, gtag. js doesn't use trackers to send data to Google Analytics. It sends data to Google Analytics properties identified by their IDs set by the config command.
The error is because you have not implemented gtag on your website. Please check the option 'Add Global Site Tracking Code gtag. js' while configuring the plugin then this error would go away(Screenshot for reference).
Do not add the Google tag (gtag. js) in Google Tag Manager via custom HTML or a template as it may not work as intended. If you want to automatically Set up conversions with URLs, you will need to install the gtag. js snippet directly on your website.
The property ID on this line is the "controller" of the gtag. js snippet. If a Universal Analytics property ID ("UA-XXXXXXXX") controls the tag, you'll be able to use connected site tags to send measurement data to a Google Analytics 4 property, without having to add any new code to the page.
The command event
supports the parameter event_callback
, a function called when processing has completed. So, compared to the old analytics.js
, you need to send an event to trigger the callback.
For example, you can use the page_view
event; however, to avoid duplicates, you must disable the automatic page_view
event by setting send_page_view
to false
.
gtag('config', GA_TRACKING_ID, {
'send_page_view': false
});
gtag('event', 'page_view', {
'event_callback': function() {
console.log('Google Analytics is ready');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With