Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to setup Ahoy with JS #577

@Necrom4

Description

@Necrom4

Ahoy is correctly working with my rails app, creating visits and events when a user moves from page to page. I now want to create more events for client-side actions, such as clicking a button, or having a heartbeat (to check for how long the user has been in the same page), so I followed the setup guide:

  • Set Ahoy.api = true
  • I tried both yarn add ahoy.js + import ahoy from "ahoy.js" and pin "ahoy", to: "ahoy.js" + import "ahoy".
  • I added this bit of code to application.js:
document.addEventListener("turbo:load", () => {
  ahoy.trackAll();
});

With the first importing method, I get the error

Uncaught TypeError: Failed to resolve module specifier "ahoy.js". Relative references must start with either "/", "./", or "../".

whilest with the second importing method I get

Uncaught TypeError: ahoy.trackAll is not a function
    at HTMLDocument.<anonymous>

How can I solve this and get ahoy.js to work so that I can track client-side events?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions