Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.04 KB

File metadata and controls

30 lines (23 loc) · 1.04 KB

Analytics Widget

Analytics widget renders the Cookies banner which collects users' consent on whether or not, they wish to allow tracking. It checks if analytics is specified in the worldConfig object, then depending on the user's choice, installs the required scripts.

Usage

  const eventSub = useRef(null);
  const analyticsConfig = useRef(worldConfig.analytics);
  const _uiEvents = useRef(uiEvents);

  // if consent to track is given;
  if (analyticsConfig.current) {
    installTrackingScript(analyticsConfig.current);
    enableTracking();
    installPageTacking();
    eventSub.current = registerEventBusSubscriber(_uiEvents.current);
  }

The hook useAnalytics then provides a trackEvent method that is useful in tracking events across the app.

  const [analyticsActions] = useAnalytics();

  analyticsActions.trackEvent({
      category: AnalyticsCategories.FILTER_SEARCH,
      action: subscribe ? 'Trending Topic Subscribed' : 'Trending Topic Unsubscribed',
    });