add parsely analytics
This commit is contained in:
parent
4839a19a1a
commit
5313e3d43d
5 changed files with 48 additions and 4 deletions
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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';
|
||||||
|
|
|
||||||
32
src/components/Analytics/providers/parsely.ts
Normal file
32
src/components/Analytics/providers/parsely.ts
Normal 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();
|
||||||
|
};
|
||||||
|
|
@ -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
8
src/globals.d.ts
vendored
|
|
@ -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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue