Where would you actually use this? As you know, we have some Amazon links here and they lead to amazon.
What if the user isn’t from the US and doesn’thave an amazon.
Com account? Just like myself, I’m from Germany.
So I should have a better experience based on the country.
Now, you might be aware of a video that we did a while back that utilizes a geolocation plugin, which I’ve here also deployed a listener with a geotag, and I now have the information available where this user that is visiting the website is actually from right now he is Germany.
So wouldn’t it be better if I know this inside of Google Tag Manager to send a user on to the de domain, in our case, that would beamazon.
De instead of amazon.
Com? Well, we can dynamically replace that link based on this geolocation attribute inside of Google Tag Manager.
So if you go here to link replace, we have a tag here that actually takes again our links with our query selector of Amazon look through them.
And we have some more configurations here.
We need to put in a search string and a replacement string, and we’ll go through all the links and replace whatever we have entered up here.
In our case, that would be.
Com/ just to make it really clear, and we want to replace this with dot de/.
Now, before we save this we actually need to attach a trigger.
It’s important that we need to have certain elements already available.
In our case, it would be that the DOM is actually ready because we want to make sure that the links have loaded so we can change them around.
And also we have that geoinformation available inside of our data.
Since the geo data Layer variable is later on.
So here’s the fourth event in the data Layer, we will utilize that to fire our tag.
Let’s go ahead and build a new trigger on the geo event where the country is Germany.
Now, we’ll utilize our custom event here.
Since it’s coming from our listener, so thegeo and only when our dlv country equals Germany.
Let’s save this and try it out.
Right now it’s still paused.
Let’s refresh, go back to a page and if the user’s from Germany we should now see all our product links leading to Amazon.
So we have successfully geolocated the user and then led him on to the desired destination based on where the users are from.
This is how you could utilize such a technique to replace a link or at least part of the link inside of your webpage.
This script will be available in a download down below in the description.
In the next lesson, we’re going to take a look at how we can attach something to a link to pass on tracking information to another page.