This feature is part of an open beta. Keep in mind that the feature is subject to change.
คำสั่งเหล่านี้มีไว้สำหรับผู้ดูแลระบบและผู้แก้ไขที่ต้องการดูวิธีตั้งค่าข้อมูลโค้ดสำหรับการเก็บรวบรวมข้อมูลที่ได้จากผู้ใช้ในเว็บไซต์โดยใช้ Google Tag Manager
การอัปเดตโค้ดจะช่วยให้อีเมล หมายเลขโทรศัพท์ และ/หรือชื่อและที่อยู่พร้อมใช้งานบนหน้าเว็บเมื่อ Analytics รวบรวมข้อมูลที่ได้จากผู้ใช้ เมื่อเทียบกับตัวเลือกการกำหนดค่าอื่นๆ
ภาพรวม
หากต้องการตั้งค่าข้อมูลโค้ดโดยใช้ Google Tag Manager ให้ทำตามขั้นตอนต่อไปนี้
- ระบุและกำหนดช่องข้อมูลที่ได้จากผู้ใช้ในโค้ดของเว็บไซต์
- ส่งช่องข้อมูลที่ได้จากผู้ใช้แต่ละช่องในตัวแปร JavaScript ที่กำหนดเองไปยัง Google Analytics
หมายเหตุ: คุณจะส่งข้อมูลลูกค้าที่แฮชหรือไม่แฮชไปยัง Google Analytics ได้ เมื่อส่งข้อมูลที่ไม่ได้แฮช Google จะแฮชข้อมูลให้คุณก่อนจัดเก็บข้อมูลไว้ในเซิร์ฟเวอร์ของ Google แต่คุณสามารถแฮชข้อมูลในฝั่งของคุณเองก่อนส่งข้อมูลไปยัง Google ได้เช่นกัน
ก่อนเริ่มต้น
คำสั่งเหล่านี้จะถือว่าคุณมีสิ่งต่อไปนี้
- การเข้าถึงซอร์สโค้ดของเว็บไซต์
- เปิดใช้งานการเก็บรวบรวมข้อมูลที่ได้จากผู้ใช้และความสามารถของข้อมูลที่ได้จากผู้ใช้ที่อนุญาต
- ตั้งค่า Google Analytics: แท็กเหตุการณ์ GA4 ในคอนเทนเนอร์ Google Tag Manager
- บทบาทผู้ดูแลระบบในพร็อพเพอร์ตี้ Google Analytics
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 ที่กำหนดเอง
ก่อนอัปเดตคอนเทนเนอร์ Tag Manager ให้อ่านวิธีอัปเดตโค้ด JavaScript ที่กำหนดเองที่คุณจะเพิ่มในคอนเทนเนอร์
- ลงชื่อเข้าใช้ Google Tag Manager
- คลิกแท็กทางด้านซ้าย จากแท็บ Workspace
- เปิดแท็ก Google Analytics: เหตุการณ์ GA4 ที่คุณรวบรวมข้อมูลลูกค้า แท็กเหตุการณ์ต้องใช้รหัสการวัดสำหรับสตรีมเว็บที่มีการรวบรวมข้อมูลผู้ใช้
- เลือกรวมข้อมูลที่ได้จากผู้ใช้จากเว็บไซต์ของคุณ
- เลือกหรือสร้างตัวแปรข้อมูลที่ได้จากผู้ใช้ในเมนูแบบเลื่อนลงข้อมูลผู้ใช้
- หากต้องการสร้างตัวแปรใหม่ ให้เลือกโค้ดในตัวแปรข้อมูลที่ได้จากผู้ใช้
- คลิกตัวแปรใหม่... ในเมนูแบบเลื่อนลงแหล่งข้อมูล
- คลิกการกำหนดค่าตัวแปร > JavaScript ที่กำหนดเอง
- กรอกชื่อให้ตัวแปร JavaScript ที่กำหนดเองด้านบนของหน้า
- กรอกข้อมูลโค้ดในกล่องข้อความ JavaScript ที่กำหนดเอง ดูวิธีการ
- บันทึกตัวแปรใหม่ จากนั้นบันทึกแท็กเหตุการณ์
- คลิกส่งด้านขวาบนเพื่อเผยแพร่การเปลี่ยนแปลง
สร้างข้อมูลโค้ดเพื่อรวบรวมข้อมูลที่ได้จากผู้ใช้
คุณสามารถใช้โค้ดต่อไปนี้เมื่อตั้งค่าตัวแปร JavaScript ที่กำหนดเองในขั้นตอนที่ 10
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.