add parsely analytics

This commit is contained in:
hobbes7878 2024-10-24 12:45:55 +01:00
parent 4839a19a1a
commit 5313e3d43d
5 changed files with 48 additions and 4 deletions

View file

@ -1,11 +1,13 @@
<script context="module"> <script context="module">
import { registerPageview as registerChartbeatPageview } from './providers/chartbeat'; import { registerPageview as registerChartbeatPageview } from './providers/chartbeat';
import { registerPageview as registerGAPageview } from './providers/ga'; import { registerPageview as registerGAPageview } from './providers/ga';
import { registerPageview as registerParselyPageview } from './providers/parsely';
/** Register virtual pageviews when using client-side routing in multipage applications. */ /** Register virtual pageviews when using client-side routing in multipage applications. */
export function registerPageview() { export function registerPageview() {
registerChartbeatPageview(); registerChartbeatPageview();
registerGAPageview(); registerGAPageview();
registerParselyPageview();
} }
</script> </script>
@ -20,10 +22,11 @@
export let authors: Author[] = []; export let authors: Author[] = [];
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { ga, chartbeat } from './providers'; import { ga, chartbeat, parsely } from './providers';
onMount(() => { onMount(() => {
ga(); ga();
chartbeat(authors); chartbeat(authors);
parsely();
}); });
</script> </script>

View file

@ -1,2 +1,3 @@
export { default as ga } from './ga'; export { default as ga } from './ga';
export { default as chartbeat } from './chartbeat'; export { default as chartbeat } from './chartbeat';
export { default as parsely } from './parsely';

View file

@ -0,0 +1,32 @@
const SITE_ID = 'reuters.com';
const attachScript = () => {
const b = document.body;
const e = document.createElement('script');
e.id = 'parsely-cfg';
e.src = `//cdn.parsely.com/keys/${SITE_ID}/p.js`;
e.setAttribute('async', '');
e.setAttribute('defer', '');
b.appendChild(e);
};
export default () => {
window.PARSELY = window.PARSELY || {
autotrack: false,
onReady() {
window.PARSELY.updateDefaults({
data: {
is_logged_in: false,
},
});
window.PARSELY.beacon.trackPageView();
},
};
attachScript();
};
export const registerPageview = () => {
if (typeof window === 'undefined' || !window.PARSELY) return;
window.PARSELY.beacon.trackPageView();
};

View file

@ -70,7 +70,7 @@
*/ */
export let authors: GraphicAuthor[] = []; export let authors: GraphicAuthor[] = [];
const getOrigin = (baseUrl) => { const getOrigin = (baseUrl: string) => {
try { try {
return new URL(baseUrl).origin; return new URL(baseUrl).origin;
} catch { } catch {
@ -82,7 +82,7 @@
}; };
$: origin = getOrigin(baseUrl); $: origin = getOrigin(baseUrl);
$: canonicalUrl = (origin + pageUrl.pathname).replace(/index\.html\/$/, ''); $: canonicalUrl = (origin + pageUrl?.pathname).replace(/index\.html\/$/, '');
const orgLdJson = { const orgLdJson = {
'@context': 'http://schema.org', '@context': 'http://schema.org',
@ -127,9 +127,9 @@
name, name,
url, url,
})), })),
creator: authors.map(({ name }) => name),
articleSection: 'Graphics', articleSection: 'Graphics',
isAccessibleForFree: true, isAccessibleForFree: true,
creator: ['Reuters Graphics'],
keywords: ['Reuters graphics', 'Reuters', 'graphics', 'Interactives'], keywords: ['Reuters graphics', 'Reuters', 'graphics', 'Interactives'],
}; };
</script> </script>

8
src/globals.d.ts vendored
View file

@ -21,6 +21,14 @@ declare global {
}; };
/** Graphics ads */ /** Graphics ads */
graphicsAdQueue: any[]; graphicsAdQueue: any[];
/** Parsely */
PARSELY: {
onLoad: () => void;
beacon: {
trackPageView: () => void;
};
updateDefaults: (params: any) => void;
};
} }
} }