Gatsby: Best way to inject a javascript library init (LogRocket) using the Gatsby lifecycle APIs

Created on 1 Aug 2019  路  1Comment  路  Source: gatsbyjs/gatsby

Hey, I want to incorporate LogRocket (logrocket.com) into my Gatsby project. The only code to get it running is:

$ npm i --save logrocket
import LogRocket from 'logrocket';
LogRocket.init('app/id');

What's the best way to inject this into Gatsby's lifecycle such that it only initialises once when a user starts a session? I've put directly into gatsby-browser.js and it seems to work fine but I'm not using any of the life cycle APIs

Most helpful comment

We encourage to use onClientEntry to handle things like analytics or one-time setups.

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏

>All comments

We encourage to use onClientEntry to handle things like analytics or one-time setups.

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinhorton picture dustinhorton  路  3Comments

kalinchernev picture kalinchernev  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

rossPatton picture rossPatton  路  3Comments

ferMartz picture ferMartz  路  3Comments