---
# System prepended metadata

title: GA / GTM
tags: [GA]

---

---
tags: GA
---
# GA / GTM 

## GTM setting


1. **請將這段程式碼放在網頁最上方的<head>中**
```
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-KH7R72Q');</script>
<!-- End Google Tag Manager -->
```

2.  **此外，請將這段程式碼複製到 <body> 開頭代碼正後方：**
```
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KH7R72Q"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
```

    
    

## Gtag

**先GTM及Gtag都埋設，待GTM完善後，再把GTAG移除**
    
1. **請將這段程式碼放在網頁最上方的<head>中**
```
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-141728928-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-141728928-1');
</script>

```