react-ga/react-ga

Support initialize call without id or expose a bool to check if ga has been initialized?

Open

#255 opened on 2018年5月4日

GitHub で見る
 (3 comments) (2 reactions) (0 assignees)JavaScript (5,116 stars) (473 forks)batch import
enhancementgood first issue

説明

  1. I have a scenario where events happen before I get the google analytics id to create the tracker.
  2. Current react-ga does support ReactGA.ga('create', ID,..) to create track.
  3. initialize from react-ga does call 'create' command directly, which is not necessary, all I want is to loadGA so that ga is in global name space and start to queue the commands..

why dont we support initialize function without specific id? All I need is to loadGA and start to queue the commands.

Or can we just export the loadGA function ?

---------More-------- I realize it makes no sense to queue other commands before the first 'create' since they will be lost. My problem is that

  1. I want to apply a middleware for the google analytics to the redux store (e.g. to fire action based events to GA).
  2. The google analytics ID will be async loaded, so I can only create a analytics instance after store creation.
  3. To ensure the pure principle of redux, middleware should/could not be applied dynamically during the runtime.

Before the ID is fetched, some actions have already fired and went through the middleware, however, currently I can't check whether ga instance has been created from react-ga. I know I can use window.ga to check it but it will be great if react-ga can expose a bool/function for that so I dont need to write window keyword in my code.

-------Another More----- Ok react-ga does return window.ga by the ReactGA.ga function with empty arguments, but can we have a more explicit function for checking if ga is available?

コントリビューターガイド

Support initialize call without id or expose a bool to check if ga has been initialized? · react-ga/react-ga#255 | Good First Issue