diff --git a/core/frontend/apps/amp/lib/helpers/amp_analytics.js b/core/frontend/apps/amp/lib/helpers/amp_analytics.js
new file mode 100644
index 0000000000..cc757104ad
--- /dev/null
+++ b/core/frontend/apps/amp/lib/helpers/amp_analytics.js
@@ -0,0 +1,35 @@
+// # Amp Components Helper
+// Usage: `{{amp_analytics}}`
+//
+// Outputs inline scripts used for analytics
+
+const proxy = require('../../../../services/proxy');
+
+const SafeString = proxy.SafeString;
+const settingsCache = proxy.settingsCache;
+
+function ampComponents() {
+ let components = [];
+
+ const ampGtagId = settingsCache.get('amp_gtag_id');
+ if (ampGtagId) {
+ components.push(`
+
+
+
+ `);
+ }
+
+ return new SafeString(components.join('\n'));
+}
+
+module.exports = ampComponents;
diff --git a/core/frontend/apps/amp/lib/helpers/amp_components.js b/core/frontend/apps/amp/lib/helpers/amp_components.js
index 149f6f140f..017c68f0a1 100644
--- a/core/frontend/apps/amp/lib/helpers/amp_components.js
+++ b/core/frontend/apps/amp/lib/helpers/amp_components.js
@@ -39,6 +39,10 @@ function ampComponents() {
components.push('');
}
+ if (proxy.settingsCache.get('amp_gtag_id')) {
+ components.push('');
+ }
+
return new SafeString(components.join('\n'));
}
diff --git a/core/frontend/apps/amp/lib/helpers/index.js b/core/frontend/apps/amp/lib/helpers/index.js
index da7567c5a1..940c8e1bde 100644
--- a/core/frontend/apps/amp/lib/helpers/index.js
+++ b/core/frontend/apps/amp/lib/helpers/index.js
@@ -6,6 +6,8 @@ function registerAmpHelpers(ghost) {
ghost.helpers.register('amp_components', require('./amp_components'));
+ ghost.helpers.register('amp_analytics', require('./amp_analytics'));
+
// we use the {{ghost_head}} helper, but call it {{amp_ghost_head}}, so it's consistent
ghost.helpers.registerAsync('amp_ghost_head', ghostHead);
}
diff --git a/core/frontend/apps/amp/lib/views/amp.hbs b/core/frontend/apps/amp/lib/views/amp.hbs
index 14dd1af297..597453ec13 100644
--- a/core/frontend/apps/amp/lib/views/amp.hbs
+++ b/core/frontend/apps/amp/lib/views/amp.hbs
@@ -622,5 +622,6 @@
Read more posts →
Published with Ghost
+ {{amp_analytics}}