cleanup
This commit is contained in:
parent
d600af5e91
commit
6b9cb80f33
1 changed files with 25 additions and 7 deletions
|
|
@ -1,13 +1,31 @@
|
|||
// Reuters Google Tag ID
|
||||
const GOOGLE_TAG_ID = 'G-WBSR7WLTGD';
|
||||
|
||||
export default () => {
|
||||
registerPageview();
|
||||
try {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
if (!window.gtag) {
|
||||
/** @type {Gtag.Gtag} */
|
||||
window.gtag = function () {
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
window.dataLayer.push(arguments);
|
||||
};
|
||||
window.gtag('js', new Date());
|
||||
// config event registers a pageview by default
|
||||
window.gtag('config', GOOGLE_TAG_ID, {
|
||||
send_page_view: false,
|
||||
});
|
||||
registerPageview();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`Error initialising Google Analytics: ${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
export const registerPageview = () => {
|
||||
if (typeof window === 'undefined' || !window.dataLayer) return;
|
||||
|
||||
window.dataLayer.push({
|
||||
event: 'page_view',
|
||||
page_location: window.location.href,
|
||||
page_title: document.title,
|
||||
if (typeof window === 'undefined' || !window.gtag) return;
|
||||
window.gtag('event', 'page_view', {
|
||||
page_location: window.location.origin + window.location.pathname,
|
||||
page_title: document?.title,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue