यह सुविधा सबके लिए उपलब्ध बीटा वर्शन में है और इसमें बदलाव हो सकते हैं.
यहां दिए गए निर्देश उन एडमिन और एडिटर के लिए हैं जो उपयोगकर्ता से मिलने वाले डेटा को इकट्ठा करने के लिए, Google Tag Manager का इस्तेमाल करके अपनी वेबसाइट में कोड स्निपेट को सेट अप करने का तरीका जानना चाहते हैं.
कॉन्फ़िगरेशन के अन्य विकल्पों का इस्तेमाल करने के बजाय, अपनी वेबसाइट का कोड अपडेट करना बेहतर विकल्प है. इससे यह पक्का होता है कि जब Analytics, उपयोगकर्ता से मिले डेटा को पेज से इकट्ठा करता है, तब उस पेज पर ईमेल पते, फ़ोन नंबर, पते, और/या नाम जैसी जानकारी उपलब्ध हो.
खास जानकारी
Google Tag Manager का इस्तेमाल करके, कोड स्निपेट सेट अप करने के लिए यह तरीका अपनाएं:
- अपनी वेबसाइट के कोड में, उपयोगकर्ता से मिले डेटा के फ़ील्ड खोजें और उनकी वैल्यू सेट करें
- Google Analytics को उपयोगकर्ता से मिले डेटा का हर फ़ील्ड, किसी कस्टम JavaScript वैरिएबल के ज़रिए भेजें
अहम जानकारी: आपके पास, ग्राहक से जुड़े डेटा को हैश करके या बिना हैश किए Google Analytics को भेजने का विकल्प होता है. जब डेटा को बिना हैश किए भेजा जाता है, तो Google उसे अपने सर्वर में स्टोर करने से पहले हैश करता है. हालांकि, आपके पास Google को डेटा भेजने से पहले, उसे हैश करने का विकल्प भी होता है.
शुरू करने से पहले
यहां बताए गए निर्देशों का पालन करने के लिए ज़रूरी है कि:
- आपके पास अपनी वेबसाइट के सोर्स कोड का ऐक्सेस हो
- आपने उपयोगकर्ता से मिले डेटा को इकट्ठा करने की सुविधा चालू की हो और उस डेटा को इस्तेमाल करने की अनुमति दी हो
- आपने Google Tag Manager कंटेनर में Google Analytics: GA4 इवेंट टैग सेट अप किया हो
- आपके पास 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 में साइन इन करें.
- फ़ाइल फ़ोल्डर टैब में, बाईं ओर मौजूद टैग पर क्लिक करें.
- वह Google Analytics: GA4 इवेंट टैग खोलें जिससे ग्राहक से जुड़े डेटा को इकट्ठा किया जाता है. साथ ही, पक्का करें कि इवेंट टैग, उस वेब स्ट्रीम के मेज़रमेंट आईडी का इस्तेमाल करता हो जहां से उपयोगकर्ता से मिले डेटा को इकट्ठा किया जाता है.
- इवेंट पैरामीटर सेक्शन को बड़ा करें और पैरामीटर जोड़ें पर क्लिक करें.
- “इवेंट पैरामीटर” फ़ील्ड में,
user_dataडालें. - “वैल्यू” फ़ील्ड में, उपयोगकर्ता से मिले डेटा का वैरिएबल चुनें या बनाएं.
- अगर नया वैरिएबल बनाया जा रहा है, तो उपयोगकर्ता से मिले डेटा के वैरिएबल में कोड चुनें.
- डेटा सोर्स ड्रॉप-डाउन मेन्यू में, नया वैरिएबल... पर क्लिक करें.
- वैरिएबल कॉन्फ़िगरेशन > कस्टम JavaScript पर क्लिक करें.
- पेज के सबसे ऊपर, कस्टम JavaScript वैरिएबल के लिए एक नाम डालें.
- कस्टम JavaScript टेक्स्ट बॉक्स में, कोड स्निपेट डालें. उपयोगकर्ता से मिले डेटा को इकट्ठा करने के लिए, कोड स्निपेट बनाने का तरीका जानें.
- नए वैरिएबल सेव करें. इसके बाद, इवेंट टैग को सेव करें.
- बदलावों को पब्लिश करने के लिए, सबसे ऊपर दाईं ओर मौजूद, सबमिट करें पर क्लिक करें.
उपयोगकर्ता से मिले डेटा को इकट्ठा करने के लिए, कोड स्निपेट बनाना
आपके पास 10वें चरण में, कस्टम JavaScript वैरिएबल को सेट अप करते समय, यहां दिए गए कोड को इस्तेमाल करने का विकल्प होता है:
function () {
return {
"email": yourEmailVariable , // replace yourEmailVariable with variable name that captures your user’s email
"phone_number": yourPhoneVariable , // repeat for yourPhoneVariable and following variable names below
"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.