Now obviously you can get way more advanced in this sort of stuff you can actually deny and or allow certain cookies and and whatever. I’ve seen examples where they do not allow you to turn off essential cookies and then you’ve got tracking cookies and under that that you can turn off and on and it sort of builds up in sort of you know more uh more I’ve forgotten the word that I was going to use more basically a more intrusive is what you’re trying to say Sam.
So, I’m going to assume that you’ve got a Google analytics account that you’ve set up a ga4 property let’s start from fresh go on why not let’s go bonkers so we’ve added our ga4 property and now we want a tracking code for this so where do we get that so I went to data streams here and we’ve got this view tag instructions come instant manually let’s take this code now I want you to put this at the top of the head so we want to apply this to every single page so let’s do that now.
I’m going to set that to true and then we’re also going to remove that show class now you can do some clever stuff with CSS to kind of have it fade out or fade in I’m going to leave that up to you, you can use gsap to kind of transition it in but unfortunately Webflow doesn’t allow you to kind of create a pre-set animation and then fire or at least I’ve not found a way to do that I’ve tried looking into the code it just it’s just a complicated mess so, we are going to remove that class so it’s just going to pop off really it looks boring but I don’t want to take your creative control away from it.
So, once again we’ve saved that let’s just let’s just prepare ourselves because we don’t want to just dive in and and check that everything’s going to work so obviously if the class gets removed then that’s going to go away so that’s really easy to see but what we want to do is if we go to if we inspect the page and we go through to application now you can go to local storage and then click on the domain you’ll see that there’s a couple of items in there that Webflow has set in the local storage.
Basically the old Google analytics code was still in the in the website because I noticed the old one was still being loaded into the page so we added the new one but what seems to have happened is even though I’ve removed my Google analytics tag from the back end of Webflow it’s still inside of the HTML of my website uh you’ve got the old one there this is my old one the you the the the non-ga4 one is still in there for some reason and this is the new one so I’m constantly getting readings basically up to Google analytics, which is kind of going to ruin how I test this and and kind of show that it’s working but we’re going to push on because maybe maybe you have not used webflow’s backend to load your Google analytics.
So, let’s just push on and see how we get on we’ve added an if statement to say only if the cookie accepted local storage item exists then what we’re going to do we’re going to create a script element this was all done whilst I was testing so I’m just going to go through it we’re going to make it async we’re going to make it that source that you should have in your which is given to you in the tag instructions and then we’re going to add it to the head and then we’re going to fire off our gtag functions right and the last thing we’re going to do here is to we’re going to anonymize IP so that we are GDPR compliant so if I save this and publish it oh there’s a syntax error.
So, now we’re just going to go one step further now and add this Google tag page to the page as soon as they click that accept button instead of waiting for a page refresh to have that happen so all we’re simply going to do is go back into Google tag manager we’re going to copy this code here and then add it into our click function so we save that…publish, we’re going to remove our cookie accepted and refresh the page so we see our banner which we do now if I go to our elements here pop into our head and just scroll down to the bottom what I expect to see is the script tag get added to the page when I click this accept button and there it is get out to the page.
So, I hope you enjoyed that as a bit of a blast from the past wasn’t it really to dip into a bit of Webflow if you’ve got any other questions about any kind of GDPR related stuff I’ll do my best to answer those in the comments but I’m by no means an expert about this about this stuff I just kind of know a few of the technicalities behind it do subscribe to the channel if you want to see more tutorials like this with no code tools like Webflow and Pinegro and also join my Discord which I’ll leave a link to in the in the description where you can kind of ask me questions or keep up to date with what’s going on the various things I have going on so until next time happy no coding.