Transcript for:
Enhancing Revenue Tracking with Google Tag Manager and GA4

even though you can track S search with Google analytics 4 fairly easily it does not automatically attribute Revenue to those Search terms but with some additional configuration that is possible let's take a look here I have a demo Google tech manager container that has just one Google analytics tag this is the configuration if you don't know how to install Google analytics with Google tag manager I will post a link to another tutorial below this video I have also enabled the pre OTE of Google tech manager and that pre OTE is enabled on this demo website where I have a fake product and if I click purchase I will be redirected to a thank you page where let's say that I have asked a developer to push the purchase data to the data layer so that data is available right here with the purchase event and if you don't know what this is then I will post a link to the documentation of Google analytics 4 where you go to make a purchase and refund and then here you will find a sample of the data layer push that you're developing should Implement on a page and this code should be activated when the purchase happens on a page of course your developer should modify this code to include only relevant information for example if I purchase a particular product then this value should be replaced with the actual ID of that product but in this video I kind of expect that you have at least basic knowledge of how Google analytics can be installed with Google tech manager and then that maybe you already have purchase tracking in implemented on a page so when this data layer push occurs on a page it says that it's a purchase event it has an eCommerce object and then it has some data about that particular purchase then we can create a Google analytics for tag that will send this purchase data to ge4 for now that event will not include the site search data but we will later add that so let's go to Google tech manager and first I will create a trigger so in the trigger section click new trigger configuration and then custom event trigger here I will insert the name of the event which is right here so purchase without quotation marks so like that and then I will name this trigger purchase then I will go to tags click new tag configuration Google analytics G4 event and here I will paste the measurement ID of my G4 data stream you can find that ID in your properties admin section then data streams click on your website data stream and then copy this measurement ID in your case the value will be different then in the event name you have to enter exactly purchase and then click more settings and send e-commerce data keep data layer as the data source this will work if your data layer structure follows the documentation of Google analytics 4 which means that the parameter names such as value then currency then items and then you have some item information most of these parameters are optional so you will need to read the documentation to learn more about which ones should you use but in my case I have item name item id price these are optional but at least have items and inside that item name item id quantity and price and here you should have at least currency value and transaction ID so once you have this then you create a tag that looks like this so this is the bare minimum if you want you can add more information and later we will add the site search keyword but for now this is the bare minimum then in the triggering click anywhere and select custom purchase trigger and then finally I will name the tag like that click save so now if I refreshed the pre mode and I made a purchase this tag would have fired and it would send the purchase data together with all of this information to Google analytics 4 now the next step which is the main topic of this video and that is site search so on this page or actually on any page of this website if I go to search and then I type some keyword for example test that keyword is available in my case at least in the URL right here so what we will do is that we will store this temporarily in a cookie and then when the purchase occurs later at some other page of this website we will read that cookie and we will send the keyword together with the purchase event so first let's read this value right here and we will need to create a variable that will just return the value of the keyword that we entered in the site search in our case the keyword is in the URL parameter which is called s in your case it might be a different parameter or maybe your website works a bit differently and then your keyword is available somewhere else so you will need to adapt but in most situations the search keyword is available in the URL and it goes after the question mark so let's create a variable that will find this query parameter and it will return its value which in this case is test so let's go to Google tech manager variables then scroll down click new variable configuration and then URL here we will select query because s right here is a query parameter it goes after the question mark so I will just type the name of the key and I will name this variable and then click save Let's test if this is working so I will click preview this will refresh the preview remote and then I will go to the website click search and then type my keyword again the page reloads and here we have that keyword now if I go to the pre mode and click for example container loaded and then go to variables I will see that my variable contains the keyword so this is okay now we have to store temporarily this value in a cookie or you could use local storage but in this video I will be using cookies below this video you will find a link to my blog post about how to set the cookies with Google tech manager and if you scroll down down here you will find the code snippet you can copy it then go to Google tag manager tags and create a new tag click new tag configuration custom HTML and then paste the code here we will need to modify some parts of the code first of all the name of the cookie instead of visitor from Google ads we could type something like GTM uncore search term something like that and then instead of a static value true we want to insert the value of our variable so we can delete this and then start typing double curly braces then we will get this list of all variables in our container and one of them is URL s then we have to set the expiration date the default in this code is 1 month but I think that's way too long I would say you could set the cookie for several hours maybe for one day personally in this example I will set the the cookie for one day so if the visitor has even multiple sessions in the same day and in the current session the visitor searches but then after several hours the visitor makes a purchase the search keyword will still be connected to that purchase this number right now shows the number of seconds that are in one month but as I've said I will set this to one day so one day contains this many seconds everything else looks okay here so now I will need to fire this tag only if the page loads and then the URL contains the search keyword because if I go for example to another page let's say the homepage there is no keyword and if here I check the value of the variable it is undefined but if I go to the search page then here I will have the keyword so basically I could say that I want to fire that tag every time the page loads and this variable is not undefined which means that it contains some value so let's go to triggering then click plus to create a new trigger trigger configuration and we can set this on page view for example and we want to fire this trigger only when our variable exists so it is not undefined let's save this trigger so first I name it and then let's click save finally let's name this tag chtml stands for custom HTML and then set cookie gdm search term click save Let's test if this is working again I will click preview then I will go to the website and first I will see that on this page my custom HTML tag did not fire because currently the URL does not contain any Search terms now if I type let's say test as a search keyword on this page I would expect my tag to Fire and it did so now if I go to the website then open developer tools so you can do that by clicking three dots more tools developer tools and then go to application cookies and expand the cookies and then select your domain here you should type in the search GTM and this is the value so this is the keyword now if I enter another keyword so for example instead of test I will enter demo then hit enter you will see that now there is a new value so what this means is that this cookie will always contain the most recent keyword that the user entered in your site search and as I can see right here my cookie expires in one day so if I come back let's say after 25 hours back to this website this cookie will no longer exist and then no search keyword will be attributed to a purchase unless of course I do do another site search before the purchase so we have the value now we need to send this together with the purchase so let's go to Google tag manager I already have the G4 purchase tag I click it and here I click the pencil to add an additional parameter in the event parameters section expand it then click add parameter and here you have to enter exactly like that search uncore term this is one of the standard parameters that Google analytics recognizes and here in the value we will need to insert a variable that reads this cookie we don't have this variable yet but we will create it right now so in Google tech manager click this button to insert a variable and then click plus click variable configuration and then select first body cookie because right now this is a first party cookie it is set on our own domain so here I will just enter GTM and search term because that's the name of the cookie that we have right here and I will name this variable click save then save the tag and let's see if this is working I will click preview the preview mode will refresh then I will go to Google analytics then admin and then keep looking for data display and debug View this is where we are going to look for the purchase event on the website I will close the developer tools and I will click the purchase link this is the order success page now if I go to the previe amount of Google tech manager I click purchase here I will see the purchase event tag there is still some bug in the previe mode so it sometimes shows the unknown tag type but ignore this after several refreshes or maybe refresh the browser or closing it and opening it again this should fix the problem but nevertheless the data was still sent to Google analytics 4 because if you click on your measurement ID here you will see that the purchase was sent well not this but this right here and on this purchase the data was sent and one of those parameters is search term and its value is demo now if I go to Google analytics debug view I have the purchase and if I click it one of the parameters is search term where I have the keyword so this looks fine and now if this was a real project I would click the submit button and publish these changes life now let's take a look how can we build a report and see how much revenue did we get from each keyword in this video I will build an example with an exploration so I already have waited 24 hours so I'm actually recording this part of the video the next day and now I can go to explore then select blank and in Dimensions click plus and add the search term Dimension so click checkbox and click import then click the Plus in the metrics section and enter revenue and select for example purchase Revenue click import now you can double click on search term then double click on purchase revenue and both of these items will be added to the report and here we see how much revenue did we get from each keyword the blank row right here means that some visitors made a purchase without using the site search and that's how you can attribute Revenue to site Search keywords the key takeaway here is that you must send the latest search keyword together with the purchase event if you found this video useful hit the like button below the video that will help me understand what videos do you like and what should I create in the future also if you want to learn more about Google tech manager or ga4 then subscribe to this Channel my name is Julius this is analytics Mania and I'll see you in the next video [Music]