fullstorydev / fullstory-browser-sdk

Official FullStory SDK for JavaScript, for web browsers
MIT License
55 stars 17 forks source link

Add a `ready` callback to the `init` function. Fixes #138 #140

Closed luser closed 2 years ago

luser commented 2 years ago

This change provides a callback for logic that needs to run after a session has started. The callback is provided with the session URL since it's available from the 'start' event.

luser commented 2 years ago

I didn't write a test for this because the existing tests don't record to a real org, so the callback won't ever fire. I tested locally by cloning angular-shoppe-demo, replacing its dependency on @fullstory/browser with my local copy, and including a ready callback in its call to init:

diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index b6a09f6..190b32d 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -15,7 +15,9 @@ export class AppComponent {

     // load the FullStory recording snippet if an orgId is set
     if (orgId) {
-      FullStory.init({ orgId, debug: false });
+      FullStory.init({ orgId, debug: false, host: 'staging.fullstory.com' },
+                     ({ sessionUrl }) => console.log(`Started session: ${sessionUrl}`)
+                    );
     }
   }
 }

Loading the site locally and opening devtools showed the session URL, as expected: Screen Shot 2022-06-08 at 5 53 52 PM

patrick-fs commented 2 years ago

Code looks good! I have one suggestion; please take a look.

Also, would you please include a remark on the ready callback in the ReadMe as well, with a basic example:

FullStory.init({ orgId, ({ sessionUrl }) => console.log(`Started session: ${sessionUrl}`));
luser commented 2 years ago

I had to rebase because I neglected to update my local tree to include #130 before making this change, so I needed to resolve that conflict. Oops!