App Lifecycle Events

For an app to refresh its data at the right time, the parent application emits an app.activated() event. The event timing differs depending on the app’s location. The app should register to listen for an app.activated event when the page containing the app is loaded for the first time, which is denoted by the app.initialized() event.

App.initialized()

This method is invoked when the page containing the app is loaded for the first time. On success, it returns the client object which can be used to register for the app.activated and app.deactivated events. As the app renders within an IFrame, all communication (Data API, Interface API, Events API) between the app and parent page occurs through the client object.

template.html Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
app.initialized().then( function(client) { //If successful, register the app activated and deactivated event callback. client.events.on("app.activated", onAppActivated); client.events.on("app.deactivated", onAppDeactivated); }, function(error) { //If unsuccessful console.log(); } );

Unless you are building an app that is completely isolated (independent of the data on the page), the core logic of the app should not be within the app.initialized() callback. It should be within the app.activated() callback to ensure that the app can react whenever the page context changes. For example, on the Lead Details page, when you navigate from one lead to another, app.activated() is triggered and the corresponding callback is executed.

App.activated()

This event is triggered when the app is brought into scope and the timing differs based on the location of the app.

Location When the event is triggered?
Lead Details page, Contact Details page, Deal Details page, Account Details page Apps in these locations are in a minimized state when the page is loaded. When you click the app icon for the first time to display the app, the app.activated event is triggered.
CTI, Chat The app.activated event is triggered after app.initialized once the page has loaded.

template.html

Copied Copy
1
2
3
4
5
client.events.on("app.activated", onAppActivated); function onAppActivated() { console.log("App Activated"); }
App.deactivated()

This event is triggered when the app is brought into scope.

template.html Copied Copy
1
2
3
4
5
client.events.on("app.deactivated", onAppDeactivated); function onAppDeactivated() { console.log("App Deactivated"); }

Log in with your Freshsales account

Enter your helpdesk URL to proceed to login

Proceed

By clicking "Proceed", you agree to our Terms of Use.