How to Track Internal Promotions with Google Analytics +GTM

Enhanced Ecommerce Promo Tracking can be done with Google Tag Manager and an Custom JavaScript variable. If you have Ads leading your website visitor deeper into your website you might want to install this tracking technique. We will use the Element Visiblity Trigger as well as a Click Trigger and a Custom JavaScript variable to deploy our tracking. No dataLayer implementation needed

Enhanced eCommerce tracking demo shop:

DataLayer Documentation:

Container Download:

Part 1

I’m going to show you how you can track internal promotions like banners on your homepage with the help of Google Analytics Enhanced eCommerce tracking and Google Tag Manager. All and more coming up right after this.

Hey there and welcome back to another video of teaching you the data-driven way of digital marketing. My name is Julian and today I want to answer a question from our MeasureMasters Community. MeasureMasters Marco asked, how can I installed Enhance eCommerce promo tracking with the help of a custom JavaScript variable? Thanks for this question, Marco. We actually need to define a few things up front. What is Enhanced eCommerce promotion tracking? Well, the Enhanced eCommerce tracking is a feature set of Google Analytics that carries throughout different reports in Google Analytics. And you can track a whole lot with this but we want to focus on the promotion tracking.

Now, what are promotions in the sense of the enhanced eCommerce tracking? Promotions are, for example, banners on your homepage, where you actually want to bring the user deeper into the website or making them aware of a certain promotion that is going on right now. So for example, you could have a banner on the homepage saying we have 20% off on our shoes right now. So if the user clicks on this, then he goes to the category and he buys later the product may be. Now, you want to track how many people actually viewed this promotion, and then clicked on it and ultimately bought right. With the enhanced eCommerce tracking, promotion tracking, you can do all of this.

Now, Marco is asking here about how he can do this with a custom JavaScript variable, which is really interesting because normally, you would need to deploy extensive dataLayers in order to track enhance eCommerce tracking. We can do this all now with the help of Google Tag Manager, at least in the promotion tracking part of this because we can make use of a custom JavaScript variable. This gives us the information that we want to send over to Google Analytics. And we can do this all with the built-in tracking mechanisms of Google Tag Manager. We can utilize the element visibility trigger to track the view, and then also the click with our click tracking trigger. And this is what I want to show you in this tutorial. Now it got a bit longer so I split it up in two parts. In this first part, we’re gonna take a look at how we can actually track the view. And this is done with the element visibility trigger. And then in the second video, we’re going to take a look at how we can track the actual click on our promotion with the help of the click trigger. Now, we got lots to cover so let’s dive in.

Welcome to the Enhanced eCommerce tracking demo shop. This is something you can access yourself at and this shop was built by Google to show off how you need to implement the enhanced eCommerce tracking to get full functionality of it. In order to see what needs to be implemented into the dataLayer, you can always click on this information icon here. And you see if the user clicks on this product, we need to deploy this kind of dataLayer. But today we want to concentrate on a particular dataLayer and this is the promo dataLayer. Right here we have a promotion going on. And when we click on it, we go to a product and then we can buy the product. Now, in the enhanced eCommerce tracking specification, you can in particular track when the user sees this promotion impression, and then also clicks on it. And the data layer that you need to implement for click is this dataLayer right here. And for the view, we actually have them on that page view when the page loads. Now we have product impressions here. But also down below here we have the promo view. So these are two dataLayers that would need to be sent over for the impression or promo data to work.

Once that data available and sent over to Google Analytics, what would it look like? If we go over to analytics, we can go under the conversions then under eCommerce and marketing then internal promotions. This is where the data would show up. If we have enhanced eCommerce tracking installed, you could see the name of the promotion then how many times it was seen, how many times it was clicked. And from there, it calculates the CTR. And if the user has bought a particular product, later on, we would be able to also see the transactions that are connected to this internal promotion click. So really interesting data. By the way, you can also use this for non-eCommerce tracking websites. It is just what Google Analytics calls and enhanced eCommerce tracking feature. And if you are flexible and can ignore the eCommerce label, you can also track, for example, internal promotions for a lead generation website or certain elements on the homepage that you want to classify as promotions.

Now, in order to get that data in there, you normally would need to deploy these dataLayers on your page. So every time somebody clicks, this dataLayer needs to be pushed into Google Tag Manager’s dataLayer. From there Google Tag Manager can pick that up via a page view or an event tag and send that on to Google Analytics. In this video, I want to show you how you can accomplish this with the help of custom JavaScript. Why do I want to show you this? Well, there are cases where you really have only one promotion on your shop. So for example, here in our shop, we have one ad that is down here, it also goes to a product page and would be perfect for our internal promotions. But we don’t want to go back and forth with the developer. We know that there’s just one ad here that we want to track. And this is actually pretty nicely done with a click trigger and an element visibility trigger. So how would we set something up like this? Let’s start at the beginning, we would need to have the information that we get from our dataLayers here inside of our custom JavaScript variable somehow. Let’s set up these variables first. So I’m going to go over to the specification of the enhanced eCommerce tracking for Google Tag Manager. It gives us here all the different dataLayers that you can set up. We want to concentrate on measuring promotions. And let’s first of all, look at measuring promotion impressions. So the actual view. It gives us this dataLayer here. Let’s simply copy it and go over to Google Tag Manager. And under variables, we’re gonna build a custom JavaScript variable.

And a custom JavaScript variable always needs an anonymous function. So you need to enter an anonymous function and a return statement. Now, in this anonymous function, we want to implement our dataLayer right here. But we don’t want to push actually to the dataLayer, we have all the information available for Google Tag Manager to send onto Google Analytics. So what we can do is actually just push our eCommerce dataLayer. In that case, we would simply get rid of that dataLayer push here. And also at the end, we want to get rid of our parentheses. And that way, now we have a simple enhanced eCommerce object installed here. Now, what do we want to do with as object? We actually want to return it. So I’m going to put the return statement in front of our object here. And it will simply return an object with our promo view information in there. It’s correctly formatted because we took it out of the specification. And we can now customize this dataLayer. Now, in this particular dataLayer, you need to know a little bit about how you can read dataLayer information. I want to actually not track two promotions, two promotions are tracked here, I only want to track one promotion. I’m going to get rid of this first promotion here. And then I want to customize this. So every promotion needs to have an ID, it doesn’t matter which ID you gave them. Only if this is an ad that comes up over and over again, you want to have the same ID. Just going to go with one here we will name this ID and our case it is an ad for the flying ninja.

Now you can put in a different creative if you have different creatives for flying ninja and a position. These, by the way, are pushed into dimensions that you can also access by the secondary dimension. So if you put in creative here we have internal promotion creative, this would be the creatives and we also have the position.

So if you want to customize them, you can. For me, this doesn’t really matter because I just have one single ad. So I’m going to just keep this a skyscraper and slot two. But if you want to customize them, go ahead. All right, let’s give this all the name. This is a custom JavaScript variable for an enhanced eCommerce promotion view. And let’s just try this out to see what the preview debug mode says about our variable so we can check whether it was correctly formatted and everything is running. So let’s go to variables. And we see here our custom JavaScript variable is now of the return type object and it’s simply has enhanced eCommerce tracking object in here. This is the information that Google Analytics needs in order to build these reports here. So now we would need to transfer to somehow to Google Analytics. How would we do that? Well, through Google Tag Manager and a Google Analytics tag. Let’s go over to tags and build a new Google Analytics tag.

And this time, it will be an event tag because we just want to send this data over. It needs to have something to transport it. And I will choose event. And this will be an event promotion view. As a tag configuration, we take our Google Analytics tag. And as a track type, this time I choose event this will be a category of enhanced eCommerce. And as the action promo view, it doesn’t really matter what you put in here, this is just the event that transport it over. But I will choose the noninteraction hit true because I don’t want to mess with my bounce rate. And as the Google analytics setting variable, I have this already prepared so it goes to the right account. Now we need to tell this tag to pick up this enhanced eCommerce tracking data that we had prepared. So I’m going to go with the enable override settings and go to more settings. And here under the eCommerce section, I can enable the enhanced eCommerce tracking. This one will be set to true I can specify if I want to use the dataLayer or read from a variable. Now in normal enhanced eCommerce tracking, you would have the dataLayer filled and then pick up the data from there. So you would use the dataLayer. But in our case, we can choose the custom JavaScript ee promo view that we have just prepared. All right, that should do it. Just to show you what data will be sent over. We also want to check under the advanced configurations the use debug version true. This we transport some information into our developer tool. So we can actually see these enhanced eCommerce tracking data being sent to Google Analytics.

So I’m going to set this to true for now. Later, if you actually publish this, I would go back and set us to false because you don’t want to have that data always in your debug console. All right, and then we just need to choose a trigger, which trigger do we choose? We have an old pages trigger that would obviously mean that the ad would be triggered, or the promo view would be triggered on all the pages. We only want it to be seen on our particular page here. How can we target this page or every time the app is seen? This is actually pretty far down. So at the beginning, the user can actually see it. So I don’t want to send an impression over once the user lands actually on a page only if you scroll down and sees this ad. And this is something you can use the element visibility trigger for. So let’s go ahead and build one. I’ll go here to the plus and as a type, we choose element visibility. And now we can select a method to actually trigger this either an ID or CSS selector. Obviously, you would need to know a little bit of CSS and figure out what the right selector is. I’m going to go here and right click and go to inspect element. And this will give me the HTML markup. And luckily, for us, we have here our section, our section of the ad. And it has an ID, media image two. So I’m just going to double-click on that and copy it and fill that into the ID. In most cases, you will probably need to use a CSS selector, which gets more complicated as you try to filter down on the elements that actually should be viewed here. So I’m going to go with the ID though. And I can choose whether they should fire every time the element is seen. This would be this one once per element. So if you have multiple elements only once it will fire or once per page. I will choose once per page for our example here. And how much should be seen of that element? 50% is fine with me. Now, I don’t need to worry really choose any filters here as this will only fire if the media image two is actually seen. Now, let’s just give this a name. This is the visibility trigger for our ad. Let’s save and save this again here. And now let’s try to this all out, refresh our page.

Well, it’s already fired here because it just down there. Let’s reload again. Somehow remembers where I was at a time. Now let’s go to another category here.

Let’s go to the t-shirts and see if this works. Okay, now we are on the t-shirts page and we just gonna scroll down. And we see element visibility now fired. And our ee promo view has fired as well. Now, this information is sent over to Google Analytics. How can we make sure that it was actually sent? That’s where this debug view came in that we have activated in our tag. We can open up the developer tools again, right-click Inspect Element and here under the console, we should now have information available of what data was actually sent over to Google Analytics. First of all, we had our pageview. This is something that fires normally on the page as we have a pageview trigger installed. And then afterward, we should see an event and this event should have our enhanced eCommerce tracking data in here as well. So here’s our event. And we also sent over an EC add promo. And this is our ID, our name and so on. So this was sent over to Google Analytics correctly. We can look this up in the account on the real-time reports here on the events. You see events last 30 minutes, we have our enhanced eCommerce tracking promo view that was sent over. Now, this only tells us that the event was received by Google Analytics. But did it actually pick up the right information from our enhanced eCommerce tracking dataLayer or the eCommerce object that we send over? Let’s go over to our conversions and under eCommerce, marketing internal promotions, we need to set the right date. Just going to pick the last date and here we see some information already been received. So we have here our internal promotion and our promotion views and the clicks or something that test it out beforehand, which we’re going to get to in a second. All right, so this is how you can already send over information about the promo view. In the next video, we’re gonna take a look at how we can send over our click data to Google Analytics as well.

Part 2

Google Analytics Enhanced Ecommerce Tracking can be installed with Google Tag Manager. In our last part (link below) we discovered how to track the view of a Promotion with the Element Visibility Trigger. In this part, we are going to track the click of the Promotion.

Welcome back. In this video, we’re going to take a look at how we can track our enhanced eCommerce promo clicks with the help of Google Tag Manager and our custom JavaScript variable. So like in the last tutorial, we already had a closer look at how we can set up such a dataLayer inside of a custom JavaScript variable. Now, we want to also track our actual clicks. Now, these enhanced eCommerce tracking dataLayers was built the same. But for our dataLayer here we have a promo click as the action. And this is something we would need to change in our tracking deployment for promo clicks. So let’s take a look at the specification here. Down below, we here have the measuring promotion clicks. And we want to do the same as with the other one. Now, I’m going to just copy the whole thing here, the whole dataLayer push. Okay, so this would be this year, going to copy this and going to go over to Google Tag Manager and build an enhanced eCommerce tracking promo view. I’m just going to copy this and going to call this enhance promo click. Now, we had our dataLayer before, I’m just going to replace this.

So here we have our dataLayer. As I said, we are not really pushing anything into the data, we just need the eCommerce object. So we can get rid of anything right here, dataLayer push and back here. Now, this is built, especially for a tracking scenario where you would forward the user on and you want to ensure that the data is actually transferred. This is done within the event callback, we can get rid of this portion as it is deployed through a variable here. So I’m going to get rid of these data points as well. And this should give us our enhanced eCommerce tracking object except for the event up here. This one is also something we wouldn’t need as we are not deploying a dataLayer. We want to simply have our eCommerce data object. Now, you see this promo object ID, project object name, and so on. This actually needs to refer to the same data that it was actually viewed. So we need to have the same data in here as we had from the one that is viewed. So I’m going to just save this, for now, go over to our view here and copy out our promotions view here. All right, let’s go over to the click data and type that in as we had before. So now we are clicking on the same data as via viewing. And if you know about enhanced eCommerce tracking, you know that you need to keep data consistent. Otherwise, the data reports inside of analytics won’t be filled correctly. So we have this now prepared. And again, we need to go through and build a tag for this. In our case, this can also be copied. So let’s copy our event here. This time, it will be a promo click event. Also going to change the event tracking parameters, this will be a promo click. And we obviously want it to pick up different data, not the view data, but the click data. So this is now specified as well. And we want to change our trigger out. So let’s click here and get rid of our visibility trigger. And in our case, it would be simply a click trigger. So let’s go here for our clicks. And I’m going to go with the all elements trigger. And let’s keep it generic for now, I’m going to build a generic click trigger.

Let’s save this. Before we move on, I need to configure my built-in variables. So we actually have our click element, click ID, and so on enabled. Let’s refresh our previous debug mode. Go back to our page and see how our variables get filled. I’m going to click on the ad. Now, this didn’t do anything. Let’s refresh here again. Oh, that’s why we had a semicolon error in our class some JavaScript variable. Let me just figure out what this is all about. It’s probably simply because we have some white space here. Let’s get rid of this and save this, refresh. And this time it does it. Okay refresh our page and I’m going to click on this with the command keypress. We have our GTM click our EE promo click already fires, that’s fine, but we want to restrict it to only fire on our ad. So we’re going to look into our triggers here, all variables and we see here our click classes get filled. And we have some information here about the click classes. Let’s go with the WP image 71. So if that’s inside of our variables filled, then we want to fire this so I’m going to turn our generic click trigger into a specific one on our ad click and I’m going to install a filter and that filter will be on the click classes if it contains WP image 71. Let’s save this. And again, try this all out.

Press this button and we see our click has fired. If I click anywhere else, it also generated GTM click but nothing fires. So this works fine. And we have now deployed our data. Let’s see if it is received by Google Analytics. Let’s go back to the real-time reporting on the events we see that there are some new events here. We had our promo click, three times promo click and that data should then also have attached our enhanced eCommerce tracking data. We can actually check inside of our let’s go on to inspect here this will open up our developer tools and we have under the console. Let’s reload our page actually. Here is our Google Analytics information. The page view has fired now also our page promo view should have fired and now click with the command keypress. Yes, we get our data in here as well the creative and so on. Everything that we have filled in. This time it’s a promo click so that data was transferred over to Google Analytics. We already saw this here in the enhance eCommerce click was just registered. Now let’s look into our conversions under eCommerce reports, marketing, and internal promotions and go to the right date.

And we see our internal promo clicks were also registered here. So this data was transferred correctly.
Now, this is it with this little tutorial. Just to recap, we have put in the right dataLayers into an enhanced eCommerce tracking variable. And this is a custom JavaScript variable that just returned our eCommerce object with the right data. And then we have triggered an event tag through Google Analytics that transport that data over to Google Analytics correctly. So it doesn’t use the dataLayer. It doesn’t read from the database, it reads from our custom JavaScript variable. And this is how you can fill these reports without actually deploying a dataLayer. But doing everything through Google Tag Manager, which is quite beneficial if you have only one promotion running on your page just like this.

All right, so there you have it. This was it with our little tutorial here on promotion tracking with enhanced eCommerce tracking features. Now, it’s always astounding to me that you can utilize all the built-in mechanisms of Google Tag Manager such as the element visibility trigger and then also the click trigger to make this deployment happen. I’d love to hear from you if you run into any problems or if you want to use this tracking deployment. If this helps you please leave us a comment down below. I always love to hear from you guys. And if you liked this video, then give us a thumbs up and also subscribe to this channel if you haven’t yet because we bring you new videos just like this one every week. Now, my name is Julian, til next time.

Julian Juenemann
About the author: Julian Juenemann

Julian started and grew venture-backed startups with his unique 'data first' approach to Online Marketing. He then founded to help marketers, like him, the data-driven way of digital marketing.

Inline Feedbacks
View all comments