stikmanw / react-fullstory-component

FullStory integration component for use with ReactJS
15 stars 10 forks source link

Window is not defined. #3

Open skeie opened 7 years ago

skeie commented 7 years ago

Hi,

First off, thanks for making this 👏 . Unforntelay I have some problems making this work. Would love to get some help.

I am trying to run this

import { FullStoryClient } from 'react-fullstory-component';

const client = new FullStoryClient({
    host: 'www.fullstory.com',
    orgKey: 'fake',
    iframe: true
});

client.render();
client.setSession('mysessionId', {
    displyName: 'visual identifier in list',
    address_str: 'some address string',
    returnVisit_bool: true,
    personId_int: '1234'
});

But window is not defined.

image

image

Do you know why?

I am using react 15.4.1

stikmanw commented 7 years ago

Sorry for the delay on this, did not see the email. What is happening is the transpiled code is assuming a window object will be provided through constructor and does not happen so it is undefined. Line 75 should get the global but it I admit it is confusing code. I will add in a fix that changes the variable names and does a check for global window vs local window object. It's bad practice to name locally scoped variables similar to browser globals and I missed it.

If you have not solved this, you can simply add window to the constructor call to force the global window object down. I will add this to the documentation also.

const client = new FullStoryClient({
    host: 'www.fullstory.com',
    orgKey: 'fake',
    iframe: true
}, window);
skeie commented 7 years ago

Thanks for the feedback 👍. This may be a dumb question, but do you need to pass window to FullStoryClient? Can't you use the global window value directly?

stikmanw commented 7 years ago

you can but the hoisting of the same named variable is causing the problem.