Changing all links to a particular website can be done in GTM (we have already discovered several techniques in previous videos). But what if you want to dynamically change a link based on where the user came from? In this video we are going to change around our amazon affiliate links based on the source the user came from so we’ll be later able to identify which traffic source converted the best.
Watch the series from the beginning: https://www.youtube.com/playlist?list=PLgr_8Hk8l4ZEv-TJjciytxsMHJ3Pysorc
Part 1 – Change Links with Google Tag Manager (Part 1) https://youtu.be/B1oMtqohZzk
Part 2 – Change Links (Search & Replace) with Google Tag Manager (Part 2) https://youtu.be/Op4X5N99jFQ
Part 3- Attached Information to a Link Dynamically with Google Tag Manager (Part 3) https://www.youtube.com/watch?v=2qnWGvPoEVY
Custom HTML Code: https://gist.github.com/measureschool/75e91074d3bad83c85fcb4c7880af565
Container Download: https://measureschool.com/wp-content/uploads/2018/12/ChangeLinks.json
Source Cookie Video: https://www.youtube.com/watch?v=x2pR4bCW7Mg
🎓 Learn more from Measureschool: https://measureschool.com/products
🚀Looking to kick-start your data journey? Hire us: https://measureschool.com/services/
📚 Recommended Measure Books: https://kit.com/Measureschool/recommended-measure-books
📷 Gear we used to produce this video: https://kit.com/Measureschool/measureschool-youtube-gear
Welcome back. In this video, we’re going to discover how we can attach something to the link. But this time dynamically. So if I click on this link, we now have our affiliate ID attached here, which we have done in the last video. But what if I wanted to change this affiliate ID around based on where the user came from? Well, you might know that in our Amazon affiliate account, you can place different tracking codes. I just have two right here, one for Adwords, and one for Facebook, and one generic one. Now, I would like to know how many people are coming through the AdWords channel onto my page, and then I forward onto Amazon and then actually buy. Now, I obviously need to somehow dynamically change the links around if this user was an AdWords or Facebook user, or something else based on where the user came from. And we will be able to utilize a technique that I have showed up in a while ago, well long time ago, which is the source cookie alternative that I’ve presented here, which writes your sources into a cookie. So let’s go back to our page already have this deployed here. So at the heart of this is a tag that sets the source cookie. And this only on the landing pages, depending on where the user came from. In our case, I can look up this cookie inside of our developer tools under application. I have here the cookies from our website, and we see a source cookie, which lists all the different sources that the user came from, given that they have been UTM tags. So in our case, if I would come from a UTM source, or let’s just make this up, I come from now, let’s say.
So we come from our email newsletter these are UTM tags, we should be able to write this down into our cookie. And we see right here it was extended to include our newsletter as well. Now if you user comes back through something else, for example, an AdWords click, which usually has the GCL ID automatic attached, then there should be also written into our source cookie, let’s see, whoops.
Here we see we have Google Ads now attached to our source cookie. Now, every time somebody enters through Google Ads, I want to now attach to my Amazon link a different affiliate ID, instead of this affiliate ID. I want to attach, let’s go over here the AdWords 20 ID. So it’s really just the difference of this right here. Now, then Amazon would report this in a different way. So I will be able to see how many clicks and how many buys went through this particular channel of mine. Since we have that information available where the user came from. In the source cookie, we can read that source cookie, I’ve already built a variable for this right here, we have our source cookie. And then we can extract the last known source, which I’ve put into this last source variable, which I can now use to build my links up programmatically. One step in between, if Google Ads is shown, I want to rewrite this into my affiliate link. So let’s go over to Google Tag Manager, first of all, and built a new lookup table variable, which will let us rewrite our affiliate links automatically. So we’ll build a lookup variable for our Amazon IDs. And this case will choose as a type the lookup table variable. And as the input will simply use our last known source and add a row here. We just need to actually know if the last known source is Facebook, Facebook.com, then I want to rewrite this into our Amazon link. Let’s go back here I want to attach this FB.
And if it’s Amazon, I want to attach aw. And this will be, in our case, let’s go back needs to be exact. So we don’t have a margin for error here, Google Ads. And the default value so if nothing is true, I simply want to turn this into our normal tag, which was this one. All right. Now that we have this prepared, we can utilize this in our attach linker, which we have already looked at in the last lesson, and simply replace our attachments string here with our lookup table variable, which is two curly brackets, we just need to find it in this menu right here. And this should do it. Let’s save this and try this out.
So this has been deployed and if I click on buy product. And now see that our AdWords was attached to this link which I wanted because I just entered the page through Adwords. What if I came through Facebook?
Now this UTM source needs to be facebook.com, actually, let’s press enter, and we just simulated it became through Facebook, let’s buy a product. And we see now Facebook is attached. And that’s the same again with a UTM that is tag from email, press enter, and we see if I buy a product, it just gives me the normal URL affiliate tag at the end. So this works as expected. And it’s highly valuable for those of you who want to track or get a better deeper understanding of your traffic channels that are going out to Amazon. Because in the reporting itself, if you go over here to the reporting of the earnings, you should cut this out, we can now see reporting for all our tracking IDs, or just who came through AdWords who came through Facebook and how much money we went with them. So hugely valuable when it comes to the tracking outside of our own website and passing that information on to something like Amazon. But really, this technique could be used in other ways as well. So you will be able to pass on information to your tracking systems, to your checkout pages that may live on a different platform or cross-domain tracking in the sense that you would be able to pass on information about the sources or about the user ID to a different website. As long as the system accepts these values, you could then see them in their system as well.
Wow, this was a lot of stuff in these little videos. I hope you enjoyed them. And if this triggered something in you, and you thought well, I want to use this tracking technique for this special case. Please let me know about the cases. I’m so interested in the cases that you will be using this checking technique down below in the comments. We can all learn from the different tracking cases that you might come up with and maybe I didn’t come up with in this tutorial. As always, if you enjoyed this video, then why not give us a thumbs up and also subscribe to the channel right over there because we bring you new videos just like this one every week now. Now, my name is Julian.
Till next time.