Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get status #82

Open
amcdnl opened this issue Jan 25, 2021 · 10 comments
Open

Add ability to get status #82

amcdnl opened this issue Jan 25, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@amcdnl
Copy link

amcdnl commented Jan 25, 2021

It would be ideal if a user could determine the status of the FS system. For example, I want to attach the fullstory url to my headers but I have no idea if FS is init'ed before I can do so.

import * as FullStory from '@fullstory/browser';

try {
    operation.setContext(({ headers = {} }) => ({
      headers: {
        ...headers,
        'x-fullstory-url': FullStory.getCurrentSessionURL(true)
      }
    }));
  } catch {
    /* noop */
  }

As a result I have to wrap it in a try catch. A simple flag like:

Fullstory.status === 'ok'

Would be awesome. I would make a string rather than boolean so you could add things like not consented/etc.

@patrick-fs
Copy link
Member

patrick-fs commented Jan 27, 2021

Hey @amcdnl thanks for the feedback! We've been discussing adding some kind of lifecycle event concept to the recording process.

would something like

FullStory.ready(({ sessionUrl }) => {
  operation.setContext(({ headers = {} }) => ({
      headers: {
        ...headers,
        'x-fullstory-url': sessionUrl
      }
    }));
})

Work for you?

@amcdnl
Copy link
Author

amcdnl commented Jan 27, 2021

The event hook is nice. I would make it a bit more generic like:

Fullstory.on('ready' or 'fail' / etc, fn);

and use something like: https://www.npmjs.com/package/event-emitter under the hood.

Though I would NOT prefer that in this case since hook is used on every API request thus the handlers would be annoying - here i would prefer a simple flag.

@patrick-fs
Copy link
Member

patrick-fs commented Jan 28, 2021

Though I would NOT prefer that in this case since hook is used on every API request thus the handlers would be annoying - here i would prefer a simple flag.

With Fullstory.status === 'ok': are there situations where you'd be ok skipping some operation if ``Fullstory.status !== 'ok'`

or would you poll status until Fullstory.status === 'ok' to ensure the operation always runs?

@amcdnl
Copy link
Author

amcdnl commented Jan 28, 2021

I would be skipping - sometimes it would never be ready if they block FS or things need to happen way before the app is init'd

@amcdnl
Copy link
Author

amcdnl commented Jan 28, 2021

This is kind of tied to this issue too: #76

@patrick-fs patrick-fs added the enhancement New feature or request label Feb 11, 2021
@patrick-fs
Copy link
Member

patrick-fs commented Feb 11, 2021

Hey @amcdnl There is a way to get the check you want, but it isn't explicit in the API. If FullStory isn't ready, then FullStory.getCurrentSessionURL(true) (or FullStory.getCurrentSessionURL()) will return null - otherwise the functions return a string (the URL value).

Can you use this logic as a proxy for Fullstory.status === 'ok'?

@amcdnl
Copy link
Author

amcdnl commented Feb 11, 2021

Last time I tried this it threw an error.

@patrick-fs
Copy link
Member

patrick-fs commented Feb 11, 2021

Last time I tried this it threw an error.

In the non-npm FullStory library (i.e. the snippet tag), getCurrentSessionURL isn't defined until the FullStory recorder is fully bootstrapped, so you would get a reference error if you tried to call the function too early. However, in the npm-distributed package, we added a guard wrapper that will return null in this case: https://github.com/fullstorydev/fullstory-browser-sdk/blob/master/src/index.js#L17

When you got the error, were you using the @fullstory/browser-sdk package? (if so, what error did you receive?)

@parifuture
Copy link

parifuture commented Jun 17, 2021

@patrick-fs I tried the way you described.

import * as FullStory from '@fullstory/browser';
import { isString } from 'lodash-es';

if (isString(FullStory.getCurrentSessionURL())) {
    FullStory.identify(`${user.principalId}`, {
      displayName: `WorkPLACE: ${user.id}`,
      role: user.primaryRole,
    });
  }

And got the following error.

Uncaught Error: FullStory is not loaded, please ensure the init function is invoked before calling FullStory API functions at ensureSnippetLoaded (index.esm.js:114) at hasFullStoryWithFunction (index.esm.js:119) at Module.<anonymous> (index.esm.js:138) at HTMLUnknownElement.callCallback (react-dom.development.js:188) at Object.invokeGuardedCallbackDev (react-dom.development.js:237)

@luser
Copy link
Contributor

luser commented Jun 6, 2022

I hadn't looked through the full backlog of issues here, but I just filed #138 which should cover this use case.

The event hook is nice. I would make it a bit more generic like:

Thanks for the feedback! We actually have in-progress work on a redesigned API to the capture script, and one piece of that work is similar to what you've described. In the near future I'm going to add contribution guidelines to this repository to help clarify what types of changes we can make here. Changes to the FullStory web capture API itself are not in scope, but we can communicate them to the team responsible. You can also raise issues like this with FullStory's Customer Support team, which is helpful because customer feedback informs our engineering teams' prioritization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants