06-19-2020 07:33 AM
Question from a beginner on the platform: Is there a way to track the amount of time spent on a specific page during a visit, using AudienceStream attributes? I want to be able to know if a visitor spent, say, 60 seconds on a page after coming in from an email, and add that user to an audience.
Could I do something like, set a timestamp when a user first visits page, then set another timestamp upon exit, and determine the length in seconds between the two?
Solved! Go to Solution.
06-20-2020 09:53 AM - edited 06-20-2020 10:04 AM
Hi @nathan ,
Great and use case. Yes, you can track the amount of time spent on a page within Audience Stream. Here are the steps I recommend to get that configured, and you can adjust if there is any additional logic you want to add.
1. Create a Visit Scoped Date Attribute with an enrichment that Captures the Current Timestamp for when a user lands on the page you want to track, with a rule like: "Current URL contains/equals "your target page" (you could also use page_name or page_type if those are relevant and unique)
2. Create a Visit Scoped Date Attribute with an enrichment that Captures the Current Timestamp when the user leaves that page with a rule like: "Referring URL contains/equals "your target page".
3. You can use a Visit scoped Number Attribute with an enrichment that sets the difference between two dates: https://community.tealiumiq.com/t5/Customer-Data-Hub/Number-Enrichment-Set-Difference-Between-Two-Da...
***You may also want to add a rule that the timestamp for when a user leaves the page is greater than the timestamp for when they land, in case the user returns.
It can go a bit deeper too, if you want to calculate the total time spent on the page, including if the user leaves the page and then comes back. You could use an additional number attribute for "Total Time Spent" that increments by the difference when it's calculated.
Hope this helps!
**just thought of one more thing. You may want to add an additional enrichment for the Date attr that captures when the user leaves the page for the case that they end their session on that page. Just make sure to only enrich that attribute when the user ends their session:
06-22-2020 01:28 PM
Thanks @namngo , this is super helpful! I didn't see the number enrichment for difference in timestamps when I was experimenting earlier. I will set up these attributes and test.
I think I will also create a number attribute that increments each visit to the relevant page. That way over time I will have number of visits to the page as well as total minutes spent on the page.
06-24-2020 02:57 PM
@namngo quick follow up question. I built attributes in our sandbox the way you are showing in the example, and was able to successfuly timestamp the start of the page visit and the end of the page visit. But the number attribute that calculates the time difference is giving me strange results when I run a Trace.
For instance, if I run a trace and go to the relevant page, and wait there for 2 or 3 minutes, it will record a number (in minutes) that doesn't look quite accurate. See screenshot showing 0.01435 minutes on the sample page for a visit that I intentionally timed for a minimum of 2 minutes. Am I reading that number correctly? Is there anything obvious I'm missing?
06-25-2020 09:41 AM
Without seeing how it's configured, it would be difficult to troubleshoot. If there are other events occurring on the page, they might be triggering the Date attribute to reset, you could try to add a rule to the Date attributes that only sets them when
ut.event equals 'view'
This will ensure that the date is being captured on page views. I tested this in my sandbox and both my Date attributes look like this:
Here is my Number Attr:
In my trace, I can see the calculation working fine after spending a minute on the page:
It sounds like there could be other events happening on the page that are resetting the date captured. If adding the additional rule does not help, you may want to submit a support ticket so an Engineer can investigate your webpage and profile.
06-25-2020 03:12 PM