diff --git a/package.json b/package.json index 91dab76a..53a54059 100644 --- a/package.json +++ b/package.json @@ -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" -} +} \ No newline at end of file diff --git a/src/components/Analytics/providers/chartbeat.ts b/src/components/Analytics/providers/chartbeat.ts index b20e2c53..4d88c65c 100644 --- a/src/components/Analytics/providers/chartbeat.ts +++ b/src/components/Analytics/providers/chartbeat.ts @@ -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, }); }; diff --git a/src/components/Analytics/providers/ga.ts b/src/components/Analytics/providers/ga.ts index 7a836725..cdfbd24f 100644 --- a/src/components/Analytics/providers/ga.ts +++ b/src/components/Analytics/providers/ga.ts @@ -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, }); };