이 기능은 공개 베타의 일부이며 변경될 수 있습니다.
다음은 사용자 제공 데이터 수집을 설정하고 gtag.js를 사용하여 웹사이트에 코드 스니펫을 추가하는 방법을 알아보려는 관리자 및 편집자를 위한 안내입니다. 웹사이트의 코드를 업데이트하면 애널리틱스에서 사용자 제공 데이터를 수집할 때 페이지에서 이메일 주소, 전화번호, 이름, 주소가 제공되도록 할 수 있습니다.
개요
웹사이트 코드를 업데이트하려면 gtag( ) 함수를 사용하여 event, config성 또는 set 명령어 내에서 각 사용자 제공 데이터 필드와 함께 user_data 값을 설정해야 합니다.
두 개 이상의 명령어 유형(예: event 및 config)에 동일한 데이터를 전달하면 event 명령어가 config 명령어를 재정의하고 config 명령어가 set 명령어를 재정의합니다. Google 태그의 매개변수 우선순위에 대해 알아보기
가입 페이지, 리드 생성 페이지, 결제 페이지 등 사용자 제공 데이터를 수집하는 모든 페이지의 코드를 업데이트해야 합니다. 세션 내에서 데이터를 두 번 이상 전송하여 데이터가 애널리틱스로 전송되도록 할 수 있습니다.
시작하기 전에
이 안내에서는 사용자가 다음 사항을 충족했다고 가정합니다.
- 웹사이트 소스 코드에 대한 액세스 권한 보유
- 사용자 제공 데이터 수집을 활성화했고 사용자 제공 데이터 기능을 허용함
Hashing the data
You can send hashed or unhashed data from a website. If you send unhashed data, Google normalizes and hashes the data before the data reaches Google's servers. To ensure Analytics interprets the data correctly and to comply with the User-provided data policy, you must use the correct key name (in the next section).
To hash the data:
- Use hex SHA256.
To normalize the data:
- Remove leading or trailing whitespaces.
- Convert the text to lowercase.
- Format phone numbers according to the E.164 standard.
Defining the fields in your code
You must provide at least one of these fields:
- Email (preferred).
- Address (first name, last name, postal code, and country are required). You can optionally provide street address, city, and region as additional match keys.
- A phone number can also be provided along with an email or full name and address.
Make sure the data is available when the Google tag fires. If the data is collected on a previous page, make sure it’s available in your code on the current page so you can configure the field.
Fields to set
The following table describes each field you can set. The key name shows how you must reference the field in your code. You must pass the data as a String type. When defining name and address, make sure to define each component as an individual variable (for example, first name, last name, and so on).
Note: If you want to send unhashed data and let Google normalize and hash the data, use the first key name for each data field. For example, email in the Email address data field below. If you want to send hashed data, use the key name that begins with sha256_.
| Data Field | Key Name | Description |
|---|---|---|
| Email address | email |
User email. Example: ‘jdoe@example.com’ |
sha256_email_address |
Hashed user email. Example: ‘a8af8341993604f29cd4e0e5a5a4b5d48c575436c38b28abbfd7d481f345d5db’ |
|
| Phone number | phone_number |
User phone number. Must be in E.164 format, which means it must be 11 to 15 digits including a plus sign (+) prefix and country code with no dashes, parentheses, or spaces. Example: ‘+11231234567’ |
sha256_phone_number |
Hashed user phone number. Example: ‘e9d3eef677f9a3b19820f92696be53d646ac4cea500e5f8fd08b00bc6ac773b1’ |
|
| First name | address.first_name |
User first name. Example: 'John' |
address.sha256_first_name |
Hashed user first name. Example: ‘96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a’ |
|
| Surname | address.last_name |
User last name. Example: 'Doe' |
address.sha256_last_name |
Hashed user last name. Example: ‘799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f’ |
|
| Street address | address.street |
User street address. Example: '123 New Rd' |
| City | address.city |
User city name. Example: `Southampton’ |
| Region | address.region |
User province, state, or region. Example: `Hampshire’ |
| Postal code | address.postal_code |
User post code. Example: 'SO99 9XX' |
| Country | address.country |
User country code. Example: 'UK'. Use 2-letter country codes, per the ISO 3166-1 alpha-2 standard. |
코드에서 필드 구현하기
고객 데이터를 수집하는 각 페이지에서 정의하려는 각 필드로 user_data 매개변수를 구성합니다.
예시 보기
다음 샘플에는 고객 데이터의 변수 이름이 포함되어 있습니다. 코드의 변수 이름이 웹사이트의 속성과 일치하는지 확인합니다. 예를 들어 이름이 'email_address'인 변수에 이메일을 저장하는 경우 이 이름으로 스니펫을 업데이트해야 합니다(예: yourEmailVariable이라고 표시됨).
변수를 사용하는 대신 필드에 문자열을 하드코딩하거나 함수를 사용할 수도 있습니다.
// Implement
<script>
gtag('set', 'user_data', {
"email": yourEmailVariable, ***yourEmailVariable을 사용자의 이메일 데이터를 저장하는 실제 JavaScript 변수 이름으로 변경합니다. 아래의 다른 변수에도 동일한 작업을 수행합니다. 값이 해싱되지 않아야 합니다.
"phone_number": yourPhoneVariable,
"address": {
"first_name": yourFirstNameVariable,
"last_name": yourLastNameVariable,
"street": yourStreetAddressVariable,
"city":yourCityVariable,
"region": yourRegionVariable,
"postal_code": yourPostalCodeVariable,
"country": yourCountryVariable
}
});
</script>
전화번호는 E.164 형식이어야 합니다. 다시 말해 11~15자리 수로, 더하기 기호(+)와 국가 코드를 포함해야 하며 대시, 괄호, 공백은 없어야 합니다.
빈 필드 삭제하기
이전 샘플 코드에서 특정 필드를 수집하지 않는 경우 필드를 비워 두지 말고 코드에서 완전히 삭제합니다. 다음은 이메일 주소와 전화번호만 수집하는 웹사이트의 예시입니다.
<script>
gtag('set', 'user_data', {
"email": {{ yourEmailVariable }},
"phone_number": {{ yourPhoneVariable }}
});
</script>
여러 값 추가하기
배열을 사용하여 여러 값(전화번호 및 이메일 주소 최대 3개씩, 주소 2개)을 제공할 수 있습니다. 값을 두 개 이상 캡처하면 일치 가능성이 높아집니다.
gtag('set', 'user_data', {
"email": [yourEmailVariable1, yourEmailVariable2],
"phone_number": [yourPhoneVariable1, yourPhoneVariable2],
"address": [
{
{
]
});
</script>