How To Remove PII From Being Sent To GA4 With Quick JavaScript
Nichelle Halstrom
50+ GA4 Setups | Custom Dashboards & Data Strategy for Startups to Fortune 500s | Marketing Analytics Consultant
Google mandates that no data be passed to GA4 that contains Personally Identifiable Information (PII) which includes email addresses and phone numbers.
Companies who send in PII may face consequences like legal issues, deletion of GA4 data, or the inability to use Google products.
I've seen many forms and email platforms which append the user's email address in the URL as a query parameter.
An example of this would be:
When loading GA4, the full page URL gets sent to Google. Meaning that you would not be considered compliant.
Thankfully, with a quick Javascript variable in Google Tag Manager, you can easily strip these parameters (and PII) and send clean URLs to Google.
(Ideally you should work with developers to ensure that this email isn't being captured.. but this is a quick fix.)
Here is a quick guide on how you can remove PII from URLs in GA4.
Step 1: Create A Custom Javascript Variable:
4. Under variable type, select "Custom JavaScript"
领英推荐
5. Copy and paste the below code into the field. Note: change "YOUR_QUERY_PARAMETER" to the unique parameter in your URL that is capturing the email address. For example:
Where "customer_email" would be the query parameter you want to exclude the text from, as this is the PII.
function(){
var blocklist = 'YOUR_QUERY_PARAMETER,email,address_line_1,address_line_2,city,state,zip_code,full_name,first_name,last_name,phone_number,postcode'.split(',');
var replaceWith = '';
var url = location.href;
var sanitizedUrl = url.replace(/((\?)|&)([^#&=]+)(?:=([^#&]*))?/g,
function(input, delim, qmark, key, val) {
if (-1 === blocklist.indexOf(key))
return input;
else
return replaceWith ? delim + key + '=' + replaceWith : qmark || '';
}).replace(/\?&*$|(\?)&+/, '$1');
return sanitizedUrl;
}
6. Name the JavaScript variable and hit "Save"
You will now need to add this script to the GA4 configuration tag, so it will block the emails from being sent within the page_location in GA4.
Transforming Data into Insights & Growth | Digital Analytics, Measurement Strategy & Implementation Expert
6 个月There's a simplified method to redact PII data (such as email addresses and query parameters) from GA4 using a built-in feature. This is also useful if the GA4 setup does not include GTM. To configure, navigate to Admin > Data Collection and modification > Data streams > [your data stream] > Events > Redact data