BranchMetrics / web-branch-deep-linking-attribution

The Branch Web SDK for deep linking and attribution. Once initialized, the Branch Web SDK allows you to create and share links with a banner (web only), over SMS, or your own methods by generating deep links. It also offers event tracking, access to referrals, and management of credits.
https://help.branch.io/developers-hub/docs/web-sdk-overview
MIT License
287 stars 100 forks source link

Window is not defined error #873

Open rycustodio opened 1 year ago

rycustodio commented 1 year ago

Describe the bug

I've added a listener and this error is showing.

Steps to reproduce

This is my code:

const [branchBanner, setBannerIsShowing] = useState(false);

  useEffect(() => {
    const initAndFetch = async () => {
      const branch = (await import('branch-sdk')).default;
      branch.closeJourney();
      branch.init(key);
      branch.track('pageview', { experiment: 'gen-banner' });

      branch.setBranchViewData({
        data: {
          x: 'open',
          y: id,
        },
      });

      branch.addListener(JourneyEvent.didShowJourney, () => {
        setBannerIsShowing(true);
      });

    };

    if (isMobile) {
      void initAndFetch();
    }
  }, [isMobile, id]);

Expected Behavior

There should be no error

Additional Information/Context

No response

SDK version used (window.branch.sdk)

2.58.2

Environment

chrome Version 110.0.5481.100

Mihai-github commented 9 months ago

+1

bogoroh commented 8 months ago

Also experience this. Any idea ?