# Migrate from UA to GA4
## Add a Google Analytics 4 property
1. Search your **UA ID** in search bar and navigate to the UA dashboard.

2. Click **Admin** at the bottom left corner of menu.

3. Click **GA4 Setup Asistant**.

4. Click **Get Started**

5. Click **Create and Continue**.

6. Select **Install a Google tag** and click **Next**.

7. Select **Install manually** tab and click **Done**.

8. Click **Go to your GA4 property**.

9. Awesome! Now you have a new GA4 dashboard.

## Install Your Google Tag
1. Get your gtag id in dashboard homepage.

2. Replace `GA_TRACKING_ID` with your own gtag id.
```html
<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"
></script>
<script>
window.dataLayer = window.dataLayer || []
function gtag() {
window.dataLayer.push(arguments)
}
gtag('js', new Date())
gtag('config', 'GA_TRACKING_ID')
</script>
```
3. Feel free with enhanced measurement like scroll, pageview and so on, check [[GA4] Enhanced event measurement](https://support.google.com/analytics/answer/9216061?hl=en) for more detail.

4. To send Google Analytics events on a web page, use the gtag.js event command with the following syntax:
```javascript
gtag('event', '<action>', {
event_category: '<category>',
event_label: '<label>',
})
```
5. See more information for how to send data through gtag in [在網站上加入 gtag.js](https://developers.google.com/analytics/devguides/collection/gtagjs?hl=zh-tw).
## Testing
1. Go to [Google Tag Assistant](https://tagassistant.google.com/) and download the chrome plugin.
2. Click **Add domain**.

3. Paste your **website's URL** and then press **Connect**.

4. Tag Assistant will open a testing tab for you.

5. Go back to Tag Assistant, Click **Continue** to start testing gtag.

6. Switch to specific **gtag id**, and event output displays below.

7. Trigger any custom event, and the result should be updated in the panel, click it for more detail.

8. Check whether event payload is correct.

## Reference
- [[GA4] Add a Google Analytics 4 property (to a site that already has Analytics)](https://support.google.com/analytics/answer/9744165#zippy=%2Cin-this-article)
- [[GA4] Setup Assistant](https://support.google.com/analytics/answer/10312255)
- [[GA4] Navigate to your account and property](https://support.google.com/analytics/answer/12813202)
###### tags: `Work` `Google Analytics 4` `Gtag`