travis-r6s / gridsome-plugin-segment-js

Add the Segment JS snippet to your Gridsome site.
1 stars 1 forks source link

trackPage: false #4

Open spurredio opened 4 years ago

spurredio commented 4 years ago

Firstly, thank for the plugin.

I have an issue. When i set trackPage: false, tracking page in templates only run once.

Do you know how i can run the page tracking each time i recall a template with a diferent path ?

BTW i've this error in devlopment : Error in mounted hook: "TypeError: Cannot read property 'page' of undefined"

Thanks in advance !

travis-r6s commented 4 years ago

@jrpersico-spurred So you are calling the track function manually? Could you paste your code?

spurredio commented 4 years ago

Yes I do !

in templates/ContentfulBlogPost.vue mounted () { this.$segment.page(this.$page.post.category, this.$page.post.title, { title: this.$metaInfo.title }) }

When I go to a post, no worries. But if I navigate from a post to another post with the same template, tracking doesn't run again.

travis-r6s commented 4 years ago

Yes, that is probably because mounted hooks are not necessarily rerun on a page change, if the layout is exactly the same, but the content changes - using the same template for instance.

I suggest you instead use the router.afterEach hook to fire the analytics tracking function. You can see an example of this in this plugins gridsome.client.js.

spurredio commented 4 years ago

Ok thank you I was able to fix the problem !

But unfortunately when trackPage is set to false, referrer is empty in segment...

Do you have any idea ?

Thanks

spurredio commented 4 years ago

Empty or always with the same value

travis-r6s commented 4 years ago

Did you add https://www.github.com/thetre97/gridsome-plugin-segment-js/tree/master/gridsome.client.js#L22?

spurredio commented 4 years ago

Nope, finally I don't use the router...

I need to set different categories for each pages or templates...

Maybe you have a tip ?

travis-r6s commented 4 years ago

In that case, sorry, no - not sure how you can get the referrer otherwise. I don't believe it is available in the $route property.