이 기능은 공개 베타의 일부이며 변경될 수 있습니다.
다음은 Google 태그 관리자를 사용하여 웹사이트에서 사용자 제공 데이터를 수집하기 위해 코드 스니펫을 설정하는 방법을 알아보려는 관리자 및 편집자를 위한 안내입니다.
다른 구성 옵션과 비교했을 때 코드를 업데이트하면 애널리틱스에서 사용자 제공 데이터를 수집할 때 페이지에서 이메일 주소, 전화번호, 이름, 주소가 제공되도록 할 수 있습니다.
개요
Google 태그 관리자를 사용하여 코드 스니펫을 설정하려면 다음 단계를 완료하세요.
- 웹사이트 코드에서 사용자 제공 데이터 필드를 식별하고 정의합니다.
- 모든 사용자 제공 데이터 필드를 맞춤 JavaScript 변수에 포함하여 Google 애널리틱스로 전달합니다.
참고: 해싱되거나 해싱되지 않은 고객 데이터를 Google 애널리틱스로 전송할 수 있습니다. 해싱되지 않은 데이터를 전송하면 Google에서 데이터를 Google 서버에 저장하기 전에 해싱합니다. 하지만 Google에 데이터를 보내기 전에 직접 데이터를 해싱할 수도 있습니다.
시작하기 전에
이 안내에서는 사용자가 다음 사항을 충족했다고 가정합니다.
- 웹사이트 소스 코드에 대한 액세스 권한 보유
- 사용자 제공 데이터 수집을 활성화했고 사용자 제공 데이터 기능을 허용함
- Google 태그 관리자 컨테이너에서 Google 애널리틱스: Google 애널리틱스 이벤트 태그를 설정함
- 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. |
맞춤 JavaScript 변수를 사용하여 이벤트 태그 업데이트하기
태그 관리자 컨테이너를 업데이트하기 전에 컨테이너에 추가할 맞춤 JavaScript 코드를 업데이트하는 방법을 알아보세요.
- Google 태그 관리자에 로그인합니다.
- 작업공간 탭에서 왼쪽에 있는 태그를 클릭합니다.
- 고객 데이터를 수집하는 Google 애널리틱스: Google 애널리틱스 이벤트 태그를 엽니다. 이벤트 태그에서 사용자 데이터가 수집되는 웹 스트림의 측정 ID를 사용해야 합니다.
- 이벤트 매개변수 섹션을 펼치고 매개변수 추가를 클릭합니다.
- '이벤트 매개변수' 필드에
user_data를 입력합니다. - '값' 필드에서 사용자 제공 데이터 변수를 선택하거나 만듭니다.
- 새 변수를 만드는 경우 사용자 제공 데이터 변수에서 코드를 선택합니다.
- 데이터 소스 드롭다운 메뉴에서 새 변수...를 클릭합니다.
- 변수 구성 > 맞춤 JavaScript를 클릭합니다.
- 페이지 상단에 맞춤 JavaScript 변수의 이름을 입력합니다.
- 맞춤 JavaScript 텍스트 상자에 코드 스니펫을 입력합니다. 자세히 알아보기
- 새 변수를 저장한 다음 이벤트 태그를 저장합니다.
- 오른쪽 상단에서 제출을 클릭하여 변경사항을 게시합니다.
사용자 제공 데이터를 수집하기 위한 코드 스니펫 만들기
10단계에서 맞춤 JavaScript 변수를 설정할 때 다음 코드를 사용할 수 있습니다.
function () {
return {
"email": yourEmailVariable , // yourEmailVariable을 사용자의 이메일을 캡처하는 변수 이름으로 바꿉니다.
"phone_number": yourPhoneVariable , // yourPhoneVariable에 대해 반복하고 아래 변수 이름을 따릅니다.
"address": {
"first_name": yourFirstNameVariable ,
"last_name": yourLastNameVariable ,
"street": yourStreetAddressVariable ,
"city": yourCityVariable ,
"region": yourRegionVariable ,
"postal_code": yourPostalCodeVariable ,
"country": yourCountryVariable
}
}
}
또는 변수를 사용하는 대신 필드에 문자열을 하드코딩하거나 함수를 사용할 수 있습니다.
// Implement
<script>
gtag('set', 'user_data', {"sha256_email_address": yourNormalizedandHashedEmailVariable,"sha256_phone_number": yourNormalizedandHashedPhoneVariable,"address": {"address.sha256_first_name": yourNormalizedandHashedFirstNameVariable,"address.sha256_last_name": yourNormalizedandHashedLastNameVariable,"city": yourCityVariable,"region": yourRegionVariable,"postal_code": yourPostalCodeVariable,"country": yourCountryVariable}
});
</script>해싱된 사용자 데이터 값을 제공하려는 경우 다음 스니펫 예를 사용하세요.
async function processUserData() {
const userData = {'sha256_email_address': await hashEmail(email.trim()),'sha256_phone_number': await hashPhoneNumber(phoneNumber),'address': {'address.sha256_first_name': await hashName(firstName),'address.sha256_last_name': await hashName(lastName),'city': city,'region': region,'postal_code': postalCode,'country': country,},
};
return userData;전화번호는 E.164 형식이어야 합니다. 다시 말해 11~15자리 수로, 더하기 기호(+)와 국가 코드를 포함해야 하며 대시, 괄호, 공백은 없어야 합니다.
Next steps
Validate that user-provided data collection is set up correctly. Show me how.