Here is a quick Google Tag Manager tip. I recently had to help a friend to set up online sales tracking on Google Analytics. My friend was using the online learning platform Teachable.
Whenever someone purchased a lesson, s/he was redirected to an URL similar to the following:
For this simple context, I just wanted to push the purchase event to Google Analytics together with the purchase price. This is how to do it:
In GTM, check into your Workspace Variables, that the built-in variable Page URL is checked :
Here, we will reuse the built-in Page URL variable and extract parameters by taking advantage of the modern browsers searchParams JS function (be aware that the compatibility is rather limited and you might want to use a longer custom function to extract the value).
Now, you can use the new variable in your GA tag. This is what I have used :
Save, and publish your changes. Don’t forget to add the goal for this event to Google Analytics:
You should be done by now :)