All threads / Segment Analytics integration, my home page pageview event is firing twice in rails 6

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Segment Analytics integration, my home page pageview event is firing twice in rails 6

Tom Connole asked in Javascript

Hi, has anyone had the issue of their home page pageview firing twice for one page view in rails 6 when they've installed Segment? I've added the Turbolinks snippet, but not sure where the problem lies.

Would having an event listener on turbolinks loading twice for different purposes cause this?

//app/javascript/packs/application.js
document.addEventListener("turbolinks:load", () => {
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
})

/app/javascript/javascript/segment.js
document.addEventListener("turbolinks:load", function() {
analytics.page()
})

I've kind of mashed together the Bootstrap tutorial, Segment tutorial and installing javascript in rails 6 tutorial together - successfully, except for this.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.