.on()

Creates a listener that responds to specific Grow events.

The .on() method lets you subscribe to various Grow events such as when the SDK is initialized or when a user logs in or out. All supported events are listed in the parameters table. Your code can then perform actions whenever the event fires.


Syntax

window.growMe.on(event, callback)

Parameters

Name Type Description
event string required

Must be one of the following values:
- loaded: Fires immediately after the Grow SDK is initialized.
- authStatusChanged: Fires whenever the user logs in or out.
- isBookmarkedChanged: Fires whenever the current page is bookmarked (or the bookmark is removed) by the current reader.
- dataLoaded: Fires whenever all initial data is loaded and the Grow widget is rendered.
callback function optional

Return Value(s)

  • loaded: No return value.
  • authStatusChanged: The callback receives an event object with a boolean isLoggedIn property. The property is true if the user is logged in and false if they are logged out.
  • isBookmarkedChanged: The callback receives an event object with a boolean isBookmarked property. The property is true if the page is bookmarked in Grow and false if it is not.
  • dataLoaded: No return value.

Example(s)

loaded

The following example logs a message to the console when the loaded event fires:

window.growMe.on("loaded", () => {
  console.log("SDK Initialized");
});
authStatusChanged

The following example logs a message to the console after the authStatusChanged event fires, returning true or false depending on whether the user is logged in:

window.growMe.on("authStatusChanged", ({ isLoggedIn }) => {
  console.log("isLoggedIn", isLoggedIn);
});
isBookmarkedChanged

The following example logs a message to the console after the isBookmarkedChanged event fires, returning true or false depending on whether the page has been bookmarked in Grow or the bookmark was removed:

window.growMe.on("isBookmarkedChanged", ({ isBookmarked }) => {
  console.log("isBookmarked", isBookmarked);
});
dataLoaded

The following example logs a message to the console after the dataLoaded event fires:

window.growMe.on("dataLoaded", () => {
  console.log("Data Loaded");
});