Initial page load tracking not calling pageTrackerTemplate
See original GitHub issueDescription
Initial page loaded is being tracked incorrectly. pageTrackerTemplate is not being called.
Expected behavior
When loading the site, I’d expect the tracking of the initial page to call pageTrackerTemplate to get my custom title value.
Actual behavior
An event is sent with the actual document title which is not what I want to send. For example, my route.meta.title is set to ‘Classes’. However, I have a router.afterEach hook that prepends 'Site Name | ’ to it and sets document.title.
Environment
Run this command in the project folder and fill in their results:
npm ls vue-gtag:
vue-gtag@1.6.2
Then, specify:
- Operating system: Linux Mint
- Browser and version: Chrome Version 81.0.4044.92 (Official Build) (64-bit)
Reproducible Demo
const routes = [
{
name: 'home',
path: '/',
component: () => import('pages/Home.vue'),
meta: {
title: () => 'Home',
},
},
]
router.afterEach((to, from) => {
if (to.meta && to.meta.title) {
const title = to.meta.title(to)
if (title) {
document.title = 'My Site | ' + title
} else {
document.title = 'My Site'
}
}
})
pageTrackerTemplate(to, from) {
const trackingData = {
page_title: to.meta.title ? to.meta.title(to) : to.name,
page_path: to.path,
page_location: window.location.href,
}
return trackingData
},
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
onRouteChangeCompleted not called on first page load #4662
Bug report Describe the bug Should Router.onRouteChangeCompleted be called on first page load? If not, what is the recommended way to track ......
Read more >Auto tracking - vue-gtag - GitBook
The automatic tracker system can use a custom template, instead of the default one: this will apply whether you are using pageviews or...
Read more >How to call a vue.js function on page load - Stack Overflow
My issue was that I did not know to use "this" in the mounted() section, and I was getting function undefined errors. "This"...
Read more >How to Track Single Page Applications with Google Tag ...
This is a tutorial on how to track single page applications (SAPs) with Google Tag Manager. Learn how with the GTM history trigger...
Read more >How to record Vuejs(SPA) page load time?
Hi All, I use Vuejs as frontend framework together with NewRelic. Although newRelic seems to record the page loading time by default. After ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@MatteoGabriele I’ve had a week off at work and I’ll be checking this out monday in the AM… I’ll let you know how it goes! thanks for the effort on this and the quick turnaround.
unrelated issues kept us from making this change, i’ll see if I can get it in first thing in the morning. thanks again for the project, documentation, and responsiveness