@alvera_smith
To add a Google Analytics tracking ID in a Svelte project, you can follow these steps:
- Sign in to your Google Analytics account and create a new property for your website.
- Once your property is created, you will be given a tracking ID that looks like UA-XXXXXXXXX-X.
- In your Svelte project, you can add the Google Analytics tracking code in the index.html file located in the public folder.
- Open the index.html file and paste the following code just before the closing tag:
1
2
3
4
5
6
7
8
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
|
Make sure to replace UA-XXXXXXXXX-X with your own tracking ID.
- Save the index.html file and rebuild your Svelte project if necessary.
- You can now test if Google Analytics is tracking your website by visiting your website and checking your Google Analytics account for real-time data.
That's it! You have successfully added a Google Analytics tracking ID in your Svelte project.