Tracking conversions in Google Analytics is often the most important reason people use Google Analytics. The default and most common way to track conversions is a Destination Goal, ie when a user reaches a page, say a thank-you page after submitting a form, Google Analytics count that as a conversion.
Unfortunately, while it is the most common, it is also is the worst way to track conversions. Sure, it’s easy and doesn’t require any technical skills, you just create the goal directly in Google Analytics like so:
But there are numerous problems with this setup.
Most obviously, if the user refreshes the thank-you page, you’ll get two conversions.
What if the page can be accessed without submitting the form first, you’ll count a conversion for each of those as well.
What if you want to report these conversions in another tool like Google Ads or Facebook?
I’d actually say 30% of my clients come to me with a misreporting of conversions because of Destination Goals like this.
Fortunately, if you’re using Google Tag Manager, there’s a much better way to report conversions that works just like Destination Goals, but avoids all the pitfalls.
With our Google Tag Manager method, instead of reporting a conversion every time users reach the conversion page, we’ll fire a Google Analytics event the first time they reach the page but not more. Here’s how to do it.
You can follow along or modify my GTM recipe to use this yourself.
Create a Cookie Based Trigger
Since we want to avoid double-counting conversions when a user refreshes the page (or whatever), we need a way to store whether or not the user has already visited the conversion page across the user’s entire session.
As Simo Ahava writes in this excellent article, there are two ways to persist data across the session using Google Tag Manager. We’ll use the cookie methodology to do so here.
First, create the Custom JavaScript Variable JS-setCookie
that Simo describes
in the post.
Next, create a Google Tag Manager 1st Party Cookie variable that will store whether or not the user has visited conversion page yet.
Now, create a trigger that fires whenever somebody visits our thank-you page (obviously it doesn’t have to be a thank-you page. It can be any page you want).
(More on the document.referrer in the bonus section)
Notice that I’m setting the Page URL
to the “thank-you” page just like I would
in a Destination Goal, BUT I’m also saying that the contactThankYou
cookie
variable we created earlier must not be true, ie the user can’t have already
visited the thank-you page. That protects us against reloads, etc.
Okay, so we have trigger, but it doesn’t actually do anything yet. First, set
the contactThankYou
cookie we created to true whenever the trigger fires with
the following tag.
I’ve set this cookie to expire in 1800000 milliseconds, ie 30 minutes. You can set your cookie to expire whenever you want. 30 minutes is Google Analytics’ default session length, so I’ve set it to that.
But suppose you had a conversion that user can legitimately achieve multiple times in a session. In that case, I might set the expiration to 2 minutes and avoid the illegitimate refresh double conversion, but still capture legitimate multiple conversions.
If you’re using the recipe, make sure you update the Domain Name
variable to
your domain name.
Create the Conversion
Now because of the contactThankYou
cookie, the trigger above will only fire
once per session, just like we want. All we have to do to turn it into a Google
Analytics conversion is use the trigger to fire a Google Analytics event…
And create an “Event” goal in Google Analytics.
And just like that, we’ve solved the double firing problem. Now when I complete my thank-you form and reach the thank-you page the first time the conversion will fire.
But if I refresh the page, it won’t.
Bonus - document referrer
Another advantage of the method described here is that I can further limit the conversion to fire ONLY when the user reaches the thank-you page FROM another specific page.
For instance, with a plain old Destination Goal, if a user arrived at my thank-you page without filling out my contact form, Google Analytics would count that as a conversion.
But if I add referrer condition to my trigger, I can make sure the conversion only fires when they came from the required previous page. (A lot like the way a “Required” Step SHOULD work in a Google Analytics destination goal)
In my case, I use Formspree (an excellent tool, btw) for my contact form. So the previous page is always Formspree’s reCAPTCHA page.
I can use the document.referrer
to make sure visitors hit the reCAPTCHA page
before the thank-you page.
First, I create a JavaScript variable to track the document.referrer variable (Simo Ahava recommends you do this anyway and I agree).
Then, I add a condition to the conversion trigger that says the document.referrer must contain formspree.io.
And bam. I’m done. Now the conversion will only fire when the user comes from the Formspree reCAPTCHA page.
You could also use the referrer to differentiate goals that have the same
thank-you page. For instance, if I had both my
contact form and my
Google Analytics Blog Package form
point to the same thank-you page, I could set a different trigger for each form
by setting the document.referrer
condition to the contact or blog package
form’s URL, respectively.
Conclusion
The destination page conversion was the best you could do when the internet was young, in a time of static websites before Google Tag Manager. But now you can do much better with this method. It is a little bit more complex (contact me if you need help), but your results will be much cleaner and trustworthy.
You can even use the same trigger to fire a Google Ads or Facebook (or any marketing service) conversion. Doing so ensures that your conversions are consistent across all your marketing tools.
The future is now.