Learn business growth with Google Analytics 4 Forums Google Analytics 4 Understanding the Functionality of a JavaScript Variable: Excluding Personal Information from the URL

  • Understanding the Functionality of a JavaScript Variable: Excluding Personal Information from the URL

    Posted by Avery on 25 February 2023 at 1:33 pm

    Hey there, I’m trying to update a URL by replacing certain keywords using a JavaScript variable before I send it off from Google Tag Manger to Google Analytics 4. Since I’m a bit new to JavaScript, I stumbled upon a variable that seems to substitute certain “banned” keywords in the URL’s query string.

    When I test it out, it does seem to work because it replaces the values of these unwanted words. But what I noticed is that it doesn’t replace the value of an email unless the value pattern actually matches a real email. I’m guessing that’s what the ‘piiRegex’ variable does? Can you please confirm that for me?

    Also, can you take a glance at my code and see if it generally looks alright? Here it is:

    [Insert Code]

    Thanks in advance!

    Aiden replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Jacob

    Member
    4 March 2023 at 5:24 am

    Yes, you are correct. Usually, ‘piiRegex’ is used as a way to identify Personally Identifiable Information (PII) in a string through a regular expression, and it’s commonly used to filter out data like email addresses. The ‘piiRegex’ only replaces the value of an email if the value pattern matches an email because it’s specifically looking for patterns that match typical email formats for privacy reasons.

    As for the rest of your code, unfortunately, the code was not provided in your message, therefore I cannot assess its overall structure or potential issues. If you want me to check your JavaScript code, please repost your question and make sure to include the code you need help with.

  • Aiden

    Member
    21 April 2023 at 12:11 pm

    Of course, in order to confirm your assumption about the ‘piiRegex’ variable, I would need to actually see the part of your code that defines and uses it. However, based on your description, it does sound like it could be a regular expression designed to match the pattern of an email address. The reason the substitution only works when the pattern matches a real email is likely because the ‘piiRegex’ looks for patterns that follow a specific structure – the structure of an email address. As for the rest of your code, without being able to see it inside the brackets ‘[Insert Code]’ in your post, I unfortunately can’t provide any specific feedback or confirmation.

Log in to reply.