Skip to content

Commit 2e49976

Browse files
authored
Merge pull request #2339 from appwrite/add-gtm
2 parents 5ffad00 + aa6f1bf commit 2e49976

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/lib/system.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ export function isMultiRegionSupported(url: URL): boolean {
3939
return false;
4040
}
4141
}
42+
43+
// there can be multiple internal cloud instances.
44+
export function isProductionCloud(url: URL): boolean {
45+
try {
46+
return url.hostname === 'cloud.appwrite.io';
47+
} catch {
48+
return false;
49+
}
50+
}

src/routes/+layout.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { trackPageView } from '$lib/actions/analytics';
77
import { Notifications, Progress } from '$lib/layout';
88
import { app, type AppStore } from '$lib/stores/app';
9-
import { isCloud } from '$lib/system';
9+
import { isCloud, isProductionCloud } from '$lib/system';
1010
import { onMount } from 'svelte';
1111
import { requestedMigration } from './store';
1212
import { parseIfString } from '$lib/helpers/object';
@@ -173,6 +173,11 @@
173173
<link rel="preload" as="style" type="text/css" href="/console/fonts/cloud.css" />
174174
<link rel="stylesheet" href={`${base}/fonts/cloud.css`} />
175175
{/if}
176+
177+
<!-- add GTM only on main instance -->
178+
{#if isCloud && isProductionCloud(page.url)}
179+
<script defer src={`${base}/scripts/gtm.js`}></script>
180+
{/if}
176181
</svelte:head>
177182

178183
<Root theme={resolveTheme($app.themeInUse)}>

static/scripts/gtm.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function (w, d, s, l, i) {
2+
w[l] = w[l] || [];
3+
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
4+
var f = d.getElementsByTagName(s)[0],
5+
j = d.createElement(s),
6+
dl = l != 'dataLayer' ? '&l=' + l : '';
7+
j.async = true;
8+
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
9+
f.parentNode.insertBefore(j, f);
10+
})(window, document, 'script', 'dataLayer', 'GTM-WQ5WKK8');

0 commit comments

Comments
 (0)