In this video, I'm going to show you how you can measure how long it took your users to
convert.
All and more, coming up.
Hey there and welcome back to another video of measureschool.com teaching you the data-driven
way of digital marketing.
My name is Julian.
And today we want to talk about how you can measure how long it took your users to convert.
Now, you might be used to the time lag report within Google Analytics that tells you how
long it actually took for your eCommerce customers to buy a product.
But wouldn't it be nice to have that data also available for your other interactions
such as a form submit, where you want to know how long did the user actually take before
he submitted this form.
Now that can give you valuable insights on how long the customer journey is.
You could even do segmentation or retargeting of customers who took a longer or shorter
period of time.
Now today, I want to show you how you can send the data via Google Tag Manager into
your Google Analytics account.
And we'll use techniques such as setting cookies, calculation with this cookies, and then sending
this all over to Google Analytics.
So
you have the data available.
Now we
got lots to cover.
So let's dive in.
All right, back in our demo shop, we have already a running installation of Google Tag
Manager with a Google Analytics page view tag deployed.
And also, if you go over to our contact form, and filled that out, we have our conversion
tracking in form of an event that fires once we submit this form.
But there's also could be a Facebook Pixel or a Google AdWords conversion tag.
And this time runs into Google Analytics where we have that data gathered here in our real-time
reporting.
What we want to add now is a data point to actually tell us how long the user has been
on the page, or how long has user journey well, until he submitted this form.
Now how can we do this?
Essentially, we need to set a cookie that writes in the background to the user's computer,
once he enters the website.
And once he then goes to this form, and submits.
We pick up the information from the cookie when it was set, and calculate the difference
between right now.
And when the cookie was set and sent it all over to Google Analytics.
That should give us the time that a user took to convert or submit this form.
So let's get started.
In Google Tag Manager, I have already prepared a script here, a listener tag that sets the
cookie for us.
This is a piece of JavaScript very standard that has a function which sets the cookie
on our browser.
Now, what I want to ride into this cookie is, first of all, the name which is in this
case first seen.
Then I want to ride in the actual time, which is right now.
And then I can define how long I want to have this cookie is set for.
Now, you could choose any number here, this is 30 days right now.
But you could also say 300 days, or go even higher.
Now, obviously, the likelihood of the cookie still being set by this amount of time is
dependent on if the user is visiting your website with a different device, or flushes
this cookie at some point, or goes into private browsing mode.
So this whole technique needs to be anyways taken as a grain of salt as any kind of tracking
that we deployed with Google Tag Manager as it's JavaScript based.
And we have certain restrictions if the user deletes these cookies.
But okay, let's leave it at 30 days.
And let's try this out.
We'll build a trigger for this.
And for now, the trigger will be pretty easy, it's just going to be a page view trigger,
which we're going to modify, I'm going to call this first seen.
All right, we're gonna go with our page view type and just deploy on our pages for now.
Let's try this out and save this.
And refresh right here.
Go back to the page.
And I'm simply going to refresh our form.
And we see our listener said, Cookie was now deployed.
What does that do in our browser?
It sets a cookie, we can see that in our developer tools.
Just go over to the menu point here or more tools, and to the developer tools, and then
navigate to the tab application.
And on the left side, you can see under the storage section the cookies.
And the domain that this was set to.
Now here's all the cookies that our website has set over this visit.
And we also see our familiar first seen cookie.
This has a cryptic number in here, and it's actually the millisecond since 19:70, which
is when the JavaScript started working.
So to say, it doesn't really have to tell you anything is just that when we measure
our time again, we want to know the difference later on.
So this is in milliseconds.
And here, we can see when it will expire the whole cookie.
So how can we now pull this cookie that we have set with the time into Google Tag Manager?
Well, that's something that we have the ability to go through a variable.
So let's go over to Google Tag Manager under the variables, we can just create a new user-defined
variable.
And this will be a simple first cookie variable for our first seen cookie.
We click on the configurations.
And here we have the ability to pull out values from a first party cookie.
We just need to know the name of that first party cookie, which in our case, is first
seen.
All right, let's save this and try this out and see how it gets filled.
Let's refresh our preview and debug mode.
Refresh our page.
Here we go.
And we can go to the variables and we can see
here's the number that is inside of the cookie right now.
You might think why did this number change?
We have still a little bit of a problem here because our listener actually fires on every
page view.
So it essentially sets the cookie again and therefore overrides our existing cookie.
This is not something that we want because we only want to fire it once.
Once the user comes to the page for the first time.
How can we detect this?
Well, if the user comes to the page for the first time, he probably doesn't have the cookie
yet.
So if Google Tag Manager can't read the cookie, and only then we want to set a cookie, because
that means the user is here for the first time.
So we can build that into our trigger.
Let's go over to the trigger
and turn this into a specific one, where we say that we only want to fire this on page
views when our cookie first scene.
So the variable that we've just created is actually undefined.
Only then I want to deploy our listener tag.
Let's save this.
And refresh,
go back to our page, reload our page.
And as we can see, our tag didn't fire.
Why?
Let's click on it.
And down here, we first need to choose an event for us, it's a page view event.
Let's go down here.
The cookie first seen does not equal undefined, which is true, because there's a number in
here.
Let's try the opposite.
Let's open up our developer tools again, and go into the application.
And we can easily delete any cookie here by just going to the cookie itself, and click
on on the x here will be deleted.
Let's reload the page.
Now,
the cookie should not have been set.
Let's go to variables.
Or it's actually a little bit misleading because our listener fired
and it says on the page view event the cookie first seen equals undefined, which was true
at that point in time.
But here we see already a value which was probably set at that time when the trigger
was evaluated.
And henceforth, this will only deploy when the user doesn't have that cookie.
Or in our definition comes to the page for the first time.
So if you go here to any other page, it shouldn't fire because we already have that cookie.
Now,
how can we transfer this to our
event that fires on the form submit?
Well, we don't want to really just sent over the time or these milliseconds that don't
really tell us anything.
This the time when the user first visited, obviously, you could download this and then
recalculate it.
But we are specifically interested in the time it took the user to convert.
And therefore, we can do this calculation instead of Google Tag Manager, and send it
all over to Google Analytics.
So once this fires, and we already have the trigger and the tag setup, we actually want
to send in data that is calculated.
And we want to fill it into our Google Analytics event tag.
In this case, we want to fill it into our label field.
And we can use variables here.
And this is what we want to make use of in order to calculate this.
So let's go over to our variable menu and create a new user-defined variable.
This is a custom JavaScript variable for our time to conversion.
And we're gonna use the custom JavaScript variable type.
And I have a little good of a template here,
which wraps everything into a try-catch error, which is best practice, really.
And in the end, we need to return a value.
That's what a return statement is in here again, already.
Now,
this function, we first want to check if the cookies even available to be read.
Obviously, this is something that we could also get from our other variable, which you
can call simply by typing in these two curly brackets, it will give you this menu here,
and we'll have a look at the cookie first seen.
If that is filled, we want to do our calculation.
Now, shorthand for this is an if statement.
We just wrap our variable in here and open up our code block, what should happen if this
is true.
So if this is filled, you want to get the time right now, which could just write into
variables here
new date, which is a function from JavaScript, and then
the milliseconds get time.
And then we want to calculate that time to conversion.
How do we calculate it?
Well, we will take our cookie time which is saved in this variable.
We would take our time right now, which we already saved in this now variable and deduct
from that our time that we have written in our cookie, which we can again call through
these two curly brackets.
And we have this menu here, where we can insert this.
So again, we take the time right now, we take the milliseconds from when the user first
landed, and the deduct this and that should give us the time that he spent to convert.
So in the end, we want to just return this time to conversion.
And it's put else statement in here.
If the cookie first seen is not filled so there is no cookie available for whatever
reason, we want to simply return undefined.
We can get rid of this return statement right here
and save this.
And let's see if this works.
Let's refresh, go back to our page.
And obviously, we can look at variables, even though we haven't yet submitted a conversion.
Let's go into any event here and under the variables and see how our time to conversion
got filled.
With the milliseconds since our first seen cookie minus a time right now.
So this is the time that we are looking at right now since we have set this cookie.
Now, just to make this a little bit more readable in JavaScript, I'm just going to open up the
JavaScript console here.
We will take that number here.
And if we divide it by 1000, we would get the seconds.
So 390 seconds, obviously, if we divide that number, even further by 60 we would get the
minutes, 6 mins 51, and so on.
And if you wanted to get the hours again, by 60, if we wanted to get the days by divided
by 24.
So in this case, our timestamp would be .004 five days before we took the action, which
equals the six minutes that we had before.
Now we can build that into our time to conversion variable.
So we have the time in minutes.
For example, if that makes sense.
Or in days, if you want to have this run longer, depending on when the converse happens, what
kind of a conversion it this, might take longer, might be faster.
So let's build in this calculation into our custom variable.
Let's go back here.
And we want to return the time to conversion, divided by 1000 divided by 60.
So we get the minutes.
And obviously, you can adjust this if you choose so.
Let's saves this again,
refresh,
go back to our page.
And let's look at the
variables again.
And we see right now we had 9 minutes, 47 seconds, in that sense, is 60 seconds.
So it's half a minute, almost.
Now that we have this number, we simply have to transfer it into our tag once the user
sends this off or submits a form.
So let's go into our tag and add that in right here into the label,
custom JavaScript time to conversion.
Let's save this and refresh
and try this all out.
Let's refresh our page
and fill this up
and send this off.
Now we should see in our Google Analytics, a new event that just happened contact us
event and it was 10 minutes 68 until I converted or submitted this form.
Later on, you can obviously see this in your behavior event reports once the data is transmitted.
And you want to see and look at all the conversions that came in and how long they took.
Now, this takes a little bit to get filled, you could even make this more sophisticated.
So if I wanted to take the next steps and actually analyze the data in a more average
fashion, I would actually not send over an event but a timing hit, which is also available
through Google Tag Manager right here.
But here would need to send the milliseconds.
So Google Tag Manager will take that up and build you some timing reports out of it.
And obviously, if you want to have it even nicer, you could take the custom JavaScript
right here and build in some other mechanisms of days or minutes if one or the other threshold
is overcome in terms of the time.
But yeah, once you have that data in your Google Analytics account, or in your Facebook
Pixel or AdWords account, you could, for example, retarget people who took a particularly long
or short time to buy your product.
In the end, if you want to have this data available for your users, you obviously would
need to submit a version so it's published to your live website.
Don't forget to give it a name
and publish it and then it's live on your website and you will get the data.
All right, so there you have it.
This is how you can measure the time that it took the user to convert on your website.
Now, I'd love to hear from you.
Is that something you would use?
In which cases would you actually use this and did you learn something?
Leave us a comment down below.
I read every one of them and I also reply to most of them if they are genuine questions.
Now, if you enjoyed this video, why not give us a thumbs up and also subscribe to this
channel because we bring you new videos just like this one
every week.
Now my name is Julian.
Till next time.
Không có nhận xét nào:
Đăng nhận xét