doesitarm/src/components/google-analytics.astro
2022-06-12 11:39:46 -05:00

28 lines
769 B
Text

---
import { gaMeasurementId } from '~/helpers/constants.js'
// const gaMeasurementId = 'G-0WLH5YTTB0'
---
<!-- Set gaMeasurementId so it's available within the browser/window context -->
<script
type="text/javascript"
set:html={ `window.gaMeasurementId = '${ gaMeasurementId }'` }
/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
type="text/partytown"
async
src={ `https://www.googletagmanager.com/gtag/js?id=${ gaMeasurementId }` }
></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag () {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', gaMeasurementId);
// console.log('I wanna to shake your hand', gaMeasurementId )
</script>