The client, Ben Bridge Jeweler, sells jewelry and accessories. They also sell Rolex products, thanks to their deal with Rolex. This deal requires them to maintain a section of their blog devoted to Rolex, and to report on traffic to and from those blog posts. Back in Universal Analytics, this specifically meant: when a customer lands on a Rolex blog post, if they visit a Rolex product detail page within the next three clicks, then send an event.
Ben Bridge’s Google Analytics and Tag Manager setup was completed as employees were coming and going, so I had two goals going in:
The meat of this solution comes from two separate tags.
The first tag fires on all pages, and keeps a running list of the last three pages the user visited, and the current page they’re on. This is just an array of URLs – when the user visits a new page, the URL is pushed to the end of the array, and if the size of the array now exceeds four, the first element is shifted (removed). Then, that array is added into window.sessionStorage so it can be accessed when the user navigates away.
The second tag only fires on Rolex product detail pages. It filters the array down to items containing the text “/news-and-events/rolex-news/”. If the array is not empty (meaning thereĀ is an element containing that text), the rolex-journey-complete event is pushed to the dataLayer.
From there, a GA4 event is triggered that is marked as a conversion.
Implemented a set of scripts to track a customer’s path across the site.
Tag: cHTML – Record last three pages
<script>
//First, find or create a variable in sessionStorage to track pages
var lastThreePages = JSON.parse(sessionStorage.getItem('lastThreePages')) || [];
//Then, add the current page to the array
lastThreePages.push(window.location.href);
//Then, if the array is longer than 3, remove the first item
if (lastThreePages.length > 3) {
lastThreePages.shift();
}
//Then, save the array back to sessionStorage
sessionStorage.setItem('lastThreePages', JSON.stringify(lastThreePages));
</script>
Tag: cHTML – rolex-journey-complete
<script>
//First, find or create a variable in sessionStorage to track pages
var lastThreePages = JSON.parse(sessionStorage.getItem('lastThreePages')) || [];
//Now filter the array to only include Rolex blog pages
var rolexBlogPages = lastThreePages.filter(function (item) {
return item.includes('/news-and-events/rolex-news/');
});
//If there was at least one blog page, push an event to the dataLayer
if (rolexBlogPages.length > 0) {
window.dataLayer.push({event: 'rolex-journey-complete'});
}
</script>
Trigger: PDP Page View
Trigger: rolex-journey-complete
Tag: GA4 – Event – rolex_journey_complete