# 구글애즈

{% hint style="info" %}
예시 코드들은 스크립트 동작을 보장하지 않습니다.
{% endhint %}

{% hint style="info" %}
본 문서에서는 구글 태그매니저 적용 방법에 대해서 기입하지 않습니다.
{% endhint %}

## 관련 문서

* 샵바이 변수 조회 가이드: <https://admin-remote.shopby.co.kr/popup/variable-guide><br>

## 주의사항

{% hint style="info" %}
구글애즈 스크립트의 경우 전환 액션 생성 시 별도로 고유의 전환라벨이 추가 됩니다.

따라서, 구글애즈에서 전환액션을 먼저 생성한 후, 스크립트 작업을 진행해 주시기 바랍니다.
{% endhint %}

## 전환 액션 생성 방법 <a href="#undefined-2" id="undefined-2"></a>

① 구글애즈 계정에 접근 하여, 도구 및 설정 > 측정 > 전환으로 접근 합니다.

<figure><img src="/files/nzKlkosbZCb4gzZxV7QI" alt=""><figcaption><p>구글애즈 화면</p></figcaption></figure>

② \[+ 새 전환 액션] 버튼을 클릭 합니다.

③ 웹사이트 전환을 선택 합니다.

<figure><img src="/files/GkJd9SjPM9n7MkGJq7Si" alt=""><figcaption><p>전환 액션 생성 화면</p></figcaption></figure>

**④** 추적할 웹사이트 도메인을 입력 합니다.

**⑤** 수동으로 전환 액션 추가를 클릭 합니다.

**⑥** 구글의 안내 절차에 따라 전환을 생성 후, 스니펫 코드를 발급 받습니다.

## 구글애즈 스크립트 예시 <a href="#undefined-3" id="undefined-3"></a>

### 상단 공통 <a href="#undefined-4" id="undefined-4"></a>

{% hint style="info" %}
스니펫 코드에서 발급 받은 구글애즈 아이디로 변경해주셔야 합니다.
{% endhint %}

```javascript
<!-- 예시 코드 -->
<script async 
        src="https://www.googletagmanager.com/gtag/js?id=계정아이디"> 
        // 계정 아이디 부분 변경 필요
</script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '계정아이디'); // 계정 아이디 부분을 변경해주세요
</script>
```

### 주문 완료 페이지 <a href="#undefined-5" id="undefined-5"></a>

{% hint style="info" %}
컨버전(전환)라벨 및 계정아이디 부분을 변경해 주셔야 합니다.
{% endhint %}

```javascript
<!-- 예시 코드 -->
<script>
  try {
    const { orderOptionsGroupByPartner = [], orderNo } = sb.order;

    const orderProducts = orderOptionsGroupByPartner.flatMap(
      ({ orderOptionsGroupByDelivery }) =>
        orderOptionsGroupByDelivery.flatMap(({ orderOptions }) => orderOptions)
    );

    const totalPrice = orderProducts.reduce((accumulator, product) => {
        return accumulator + (product.orderCnt * product.price.buyPrice);
    }, 0);
      
    gtag("event", "conversion", {
      send_to: "계정 아이디/컨버전 라벨",
      value: totalPrice,
      currency: "KRW",
      transaction_id: orderNo,
    });
  } catch (error) {
    console.error(error);
  }
</script>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://marketing-help.nhn-commerce.com/conversion-tracking-setup/shopby-ads-script/google-ads.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
