diff --git a/.changeset/gentle-guests-wonder.md b/.changeset/gentle-guests-wonder.md
new file mode 100644
index 00000000..ef703680
--- /dev/null
+++ b/.changeset/gentle-guests-wonder.md
@@ -0,0 +1,5 @@
+---
+'@reuters-graphics/graphics-components': patch
+---
+
+Updates analytics scripts to work with GDPR-compliant GTM container
diff --git a/src/components/Analytics/Analytics.svelte b/src/components/Analytics/Analytics.svelte
index 7c85d2aa..75afbe74 100644
--- a/src/components/Analytics/Analytics.svelte
+++ b/src/components/Analytics/Analytics.svelte
@@ -1,6 +1,10 @@
+
+
+
+ {@html `<${'script'}>${GTM_SCRIPT}`}
+
+
+
+
+
+
diff --git a/src/components/Analytics/providers/chartbeat.ts b/src/components/Analytics/providers/chartbeat.ts
index aedea3a0..61089b31 100644
--- a/src/components/Analytics/providers/chartbeat.ts
+++ b/src/components/Analytics/providers/chartbeat.ts
@@ -1,20 +1,6 @@
// Reuters Chartbeat UID
const UID = 52639;
-const URL = '//static.chartbeat.com/js/chartbeat.js';
-
-const attachScript = () => {
- // If script is already attached, skip
- if (document.querySelector(`script[src="${URL}"]`)) return;
- // ... else attach it.
- const e = document.createElement('script');
- const n = document.getElementsByTagName('script')[0];
- e.type = 'text/javascript';
- e.async = true;
- e.src = URL;
- n.parentNode!.insertBefore(e, n);
-};
-
export default (authors: { name: string }[]) => {
window._sf_async_config = {
uid: UID,
@@ -26,12 +12,6 @@ export default (authors: { name: string }[]) => {
authors: authors.map((a) => a?.name || '').join(','),
...(window._sf_async_config || {}),
};
-
- try {
- attachScript();
- } catch (e) {
- console.warn(`Error initialising Chartbeat Analytics: ${e}`);
- }
};
export const registerPageview = () => {
diff --git a/src/components/Analytics/providers/ga.ts b/src/components/Analytics/providers/ga.ts
index 6bd02d1d..159f1d55 100644
--- a/src/components/Analytics/providers/ga.ts
+++ b/src/components/Analytics/providers/ga.ts
@@ -1,25 +1,10 @@
// Reuters Google Tag ID
const GOOGLE_TAG_ID = 'G-WBSR7WLTGD';
-const URL = `https://www.googletagmanager.com/gtag/js?id=${GOOGLE_TAG_ID}`;
-
-const attachScript = () => {
- // If script is already attached, skip
- if (document.querySelector(`script[src="${URL}"]`)) return;
- // ... else attach it.
- const e = document.createElement('script');
- const n = document.getElementsByTagName('script')[0];
- e.type = 'text/javascript';
- e.async = true;
- e.src = URL;
- n.parentNode!.insertBefore(e, n);
-};
-
export default () => {
try {
window.dataLayer = window.dataLayer || [];
if (!window.gtag) {
- attachScript();
/** @type {Gtag.Gtag} */
window.gtag = function () {
// eslint-disable-next-line prefer-rest-params