few last things on analytics

This commit is contained in:
Jon McClure 2023-05-30 12:34:36 +01:00
parent fbea3a560f
commit a3289eaa6b
3 changed files with 22 additions and 17 deletions

View file

@ -101,6 +101,10 @@
"./actions/cssVariables": "./dist/actions/cssVariables/index.js",
"./actions/resizeObserver": "./dist/actions/resizeObserver/index.js",
"./components/@types/global.ts": "./dist/components/@types/global.ts",
"./components/Analytics/Analytics.svelte": "./dist/components/Analytics/Analytics.svelte",
"./components/Analytics/providers/chartbeat.ts": "./dist/components/Analytics/providers/chartbeat.ts",
"./components/Analytics/providers/ga.ts": "./dist/components/Analytics/providers/ga.ts",
"./components/Analytics/providers/index.ts": "./dist/components/Analytics/providers/index.ts",
"./components/Article/Article.svelte": "./dist/components/Article/Article.svelte",
"./components/BeforeAfter/BeforeAfter.svelte": "./dist/components/BeforeAfter/BeforeAfter.svelte",
"./components/Block/Block.svelte": "./dist/components/Block/Block.svelte",
@ -132,10 +136,6 @@
"./components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte": "./dist/components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte",
"./components/ReutersLogo/ReutersLogo.svelte": "./dist/components/ReutersLogo/ReutersLogo.svelte",
"./components/SEO/SEO.svelte": "./dist/components/SEO/SEO.svelte",
"./components/SEO/analytics/chartbeat": "./dist/components/SEO/analytics/chartbeat.js",
"./components/SEO/analytics/ga": "./dist/components/SEO/analytics/ga.js",
"./components/SEO/analytics": "./dist/components/SEO/analytics/index.js",
"./components/SEO/analytics/publisherTags": "./dist/components/SEO/analytics/publisherTags.js",
"./components/Scroller/Background.svelte": "./dist/components/Scroller/Background.svelte",
"./components/Scroller/Embedded/Background.svelte": "./dist/components/Scroller/Embedded/Background.svelte",
"./components/Scroller/Embedded/Foreground.svelte": "./dist/components/Scroller/Embedded/Foreground.svelte",
@ -207,6 +207,7 @@
"./components/Video/Controls.svelte": "./dist/components/Video/Controls.svelte",
"./components/Video/Video.svelte": "./dist/components/Video/Video.svelte",
"./components/Visible/Visible.svelte": "./dist/components/Visible/Visible.svelte",
"./globals.d.ts": "./dist/globals.d.ts",
"./scss/mixins": "./dist/scss/_mixins.scss",
"./scss/variables": "./dist/scss/_variables.scss",
"./scss/bootstrap/main": "./dist/scss/bootstrap/_main.scss",
@ -238,4 +239,4 @@
".": "./dist/index.js"
},
"svelte": "./dist/index.js"
}
}

View file

@ -16,14 +16,16 @@ const attachScript = () => {
};
export default (authors: { name: string }[]) => {
const config = window._sf_async_config = (window._sf_async_config || {});
config.uid = UID;
config.domain = 'reuters.com';
config.flickerControl = false;
config.useCanonical = true;
config.useCanonicalDomain = true;
config.sections = 'Graphics';
config.authors = authors.map((a) => a.name).join(',');
window._sf_async_config = {
uid: UID,
domain: 'reuters.com',
flickerControl: false,
useCanonical: true,
useCanonicalDomain: true,
sections: 'Graphics',
authors: authors.map((a) => a?.name || '').join(','),
...(window._sf_async_config || {}),
};
try {
attachScript();
@ -31,9 +33,9 @@ export default (authors: { name: string }[]) => {
};
export const registerPageview = () => {
if (!window.pSUPERFLY) return;
if (typeof window === 'undefined' || !window.pSUPERFLY) return;
window.pSUPERFLY({
path: window.location.pathname,
title: document.title,
title: document?.title,
});
};

View file

@ -27,15 +27,17 @@ export default () => {
window.gtag('js', new Date());
// config event registers a pageview by default
window.gtag('config', GOOGLE_TAG_ID, {
page_location: window.location.origin + window.location.pathname,
send_page_view: false,
});
registerPageview();
}
} catch (e) { console.warn(`Error initialising Google Analytics: ${e}`); }
};
export const registerPageview = () => {
if (!window.gtag) return;
if (typeof window === 'undefined' || !window.gtag) return;
window.gtag('event', 'page_view', {
page_location: window.location.origin + window.location.pathname,
page_title: document?.title,
});
};