GithubHelp home page GithubHelp logo

Comments (4)

sevab avatar sevab commented on July 2, 2024 3

Agree with @jsharpe-mr that would be nice to have more granular control over documentReady().

In our case we install & use ahoy via npm/yarn. However, importing the module automatically executes documentReady() and starts it, before we get a chance to set up ahoy with variables necessary for its correct function (e.g. urlPrefix, authentication headers).

At least when building as a node module, would be nice to skip documentReady() to make the library more standalone.

from ahoy.js.

ankane avatar ankane commented on July 2, 2024

Hey @jsharpe-mr, I think a vast majority of users either don't need to configure Ahoy or are able to configure it before the document is ready, so I don't think it makes sense for all of those users to have to call it manually.

from ahoy.js.

hwhelchel avatar hwhelchel commented on July 2, 2024

I'm using ahoy.js in webpacker installed via yarn. What is the recommended practice for configuring ahoy.js with this setup?

I think I'm running into the same issue where documentReady runs before I'm able to configure the library.

from ahoy.js.

zokioki avatar zokioki commented on July 2, 2024

I'm also using ahoy.js in a webpacker environment and am facing the same issue. The way I'm handling this is by temporarily assigning the config object to window.ahoy, allowing ahoy to pull that object in on instantiation (see relevant ahoy logic), and resetting window.ahoy to its original value:

initAhoy() {
  // desired configuration
  let ahoyConfig = { cookies: false };

  // back up current window.ahoy value
  let oldAhoy = window.ahoy;

  // assign window.ahoy to the config object, 
  // ahoy.js will use it for configuration once instantiated
  window.ahoy = ahoyConfig;
  this.ahoy = require('ahoy.js').default;

  // restore previous window.ahoy value
  window.ahoy = oldAhoy;
}

I'm not sure if this is the best approach, but it works fairly well for my use case.

from ahoy.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.