Edit
Contact us
Salocin Group Leaders in data and AI-enabled connected customer experiences
Edit Engineers of connected customer experiences
Join the Dots Independent, data-led media thinking for sustainable growth
Wood for Trees Optimisers of future fundraising performance
  • Home
  • Our services
    • Cloud solutions
    • Data science
    • Modern Data Platform
    • Privacy and AI compliance
  • Our partners
    • Apteco
    • Creatio
    • Microsoft
    • Salesforce
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Salocin Group
    • Careers
  • Contact Salocin Group
  • Home
  • Who we are
    • B Corp
    • Careers
  • Our work
  • What we do
    • Intelligent data
    • Marketing technology
    • Transformational CRM
    • Our technology partners
    • Privacy review
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • Contact Edit
  • Home
  • Broadcast media
  • Digital media
  • Print
    • Direct mail
  • Data
    • Our work with Herdify
    • EPiC
  • Media agency
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Join the Dots
    • Careers
  • Contact Join the Dots
  • Home
  • Services
    • Actionable insight
    • Data discovery
    • Data engineering
    • Data hygiene
    • Privacy review
  • Products
    • InsightHub
    • Apteco
    • Microsoft
    • Data management
    • Consent and preference management
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Wood for Trees
    • Operating principles
    • Careers
  • Contact Wood for Trees
Blog

How to encrypt data capture using Google Tag Manager

By Edit | 26 Mar 2018

When I attended CROElite17, one of my favourite points someone (forget who – if it was you please let me know, I’ll give you a link) raised was that you can use Google Tag Manager to pull in form inputs when an error occurs, and then send that data to Google Analytics. This means you get loads of data as to why forms break and if there’s a consistency (e.g. it always breaks when people put brackets on their phone number or with two character surnames) fixes can be made, and conversion rate increases.

There are a few large problems with this idea:

  • GDPR
  • Data Protection
  • Terms of Use

You really shouldn’t record people’s names, e-mail addresses, phone numbers, financial details and all that stuff in GA. You’ll get in trouble.

To get useful information, you might not need the actual names, e-mail addresses, etc. tracked in Google Analytics. You need to be able to recognise the pattern they are producing (e.g. the character length of an erroring credit card, or a two-character TLD in an e-mail address) in order to properly test your theories and fix errors.

How to encrypt personal information using Google Tag Manager

  • To capture the data, create a new variable with the data you want to capture.
    • Simo gives a good overview of tracking form engagement here
    • This variable should NOT be linked to any tags! It’s only for transformation using the next variable we create
    • Capturing it as a variable means it’s stored temporarily on the user side so it can be transformed into its encrypted state
  • To transform the data, create a New Variable.
    • Variable Type: Custom Javascript
    • Custom Javascript:

  function(){

   var str = {{YOUR VARIABLE}};

   var newString = str.replace(/[a-z,A-Z]/g, “X”).replace(/[0-9]/g, “1”);

   return newString;

}

  • Note: Replace YOUR VARIABLE with the name of the first variable you created above. What the Javascript does is it translates all letters to “X” and all numbers to “1”. You can amend this as makes sense to you

Above: The JavaScript transforms the “Page Query” variable.

Above: An e-mail address transformed.

  • Create a trigger for when a form is submitted, but not validated or an error occurs
  • Create a tag that pushes an event on this trigger, with the encrypted variable as data

Now you can look at your events report to see what sorts of inputs are most frequently causing errors, without violating Google Analytics Terms of use, or GDPR.

Thanks for reading, if you enjoy this, I’d recommend getting a ticket to CROElite18, the event that helped spark my interest in this topic (cheers guys!).

Share this

  • Email
  • WhatsApp
  • LinkedIn
  • Facebook
  • X (Twitter)

More insights

AI isn’t going to take your job (unless you really want it to) 
Blog

AI isn’t going to take your job (unless you really want it to) 

By Edit | 18 Jun 2024
Customer relationship marketing: How generative AI is revolutionising engagement  
Blog

Customer relationship marketing: How generative AI is revolutionising engagement  

By Edit | 4 Apr 2024
Personalisation as a process
Blog

Personalisation as a process

By Edit | 8 Mar 2024
  • Privacy policy
  • Cookie policy
  • Ts&Cs
  • Report a concern

© 2025 Edit, part of Salocin Group Ltd. All rights reserved. Company no.: 0362​4881. VAT no.: 4208​34911.

Salocin Group Certified B Corporation | Cyber Essentials Certified | British Assessment Bureau, ISO 27001 Information Security Management
Salocin Group
Your cookie preferences

We use cookies to ensure this website functions properly, to analyse website traffic and for marketing purposes.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}