---
updatedAt: 2025-05-13T20:34:58.000Z
agentTools:
  projectIndex: https://mobile.developer.smartlook.com/llms.txt
---

# Lifecycle and Recording

## SDK setup (on application start)

The best place to setup the SDK is in [deviceready](https://cordova.apache.org/docs/en/5.1.1/cordova/events/events.deviceready.html) callback:

```typescript
if(document.readyState === "complete") {
  document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    Smartlook.setProjectKey({key: "API_KEY"});
  	Smartlook.start();
}
```

## Project key

Your unique project key is needed for the SDK to upload and process the recordings. You can find your project key in the mobile project settings in the [Smartlook app](https://app.smartlook.com/).

```typescript
Smartlook.setProjectKey({key: "API_KEY"});
```

## Starting and stopping recordings

Recordings can be started or stopped at any time. Multiple subsequent `start()` or `stop()` calls will be ignored.

```typescript
Smartlook.start();
Smartlook.stop();
```

When a user closes your app, the user session automatically stops recording. You don't need to call the `stop()` method when the user stops using your app.

> 📘 Recording start and project key
>
> User sessions can be recorded even if you haven't set the project key. Recorded data are saved but not sent. Once you set the project key, the data is sent.

## Checking if the SDK is recording

To see if the SDK is recording:

```typescript
const isRecording = await Smartlook.isRecording();
```

> 📘 Why isn't the SDK recording?
>
> You can see why your SDK is not recording by calling `await Smartlook.getRecordingStatus()`. For more information on possible reasons the SDK is not recording and `status`, see [Status](https://mobile.developer.smartlook.com/reference/ionic-preferences-state#status).

## Opening new sessions

You can close the current session and start a new session:

```typescript
Smartlook.openNewSession();
```

## Session URL

The `URL` of the currently recorded session can be obtained with or without a timestamp:

```typescript
const sessionUrl = await Smartlook.getSessionUrl();
const sessionUrlWithTimestamp = await Smartlook.getSessionUrlWithTimestamp();
```

> 🚧 Nullability and shareability
>
> `URL`s are only available when the SDK is able to "communicate" with the Smartlook backend. Otherwise, they are `null`.
>
> `URL`s are not publicly sharable and login to the dashboard is mandatory before opening these.

## Session Listener

A *listener* can be registered to listen to the session URL changes.

```typescript
// A callback function that gets called when the session URL changes.
function urlChangedCallback(sessionUrl: string) {
  console.log('Emitted session url', sessionUrl);
}

Smartlook.registerSessionUrlChangedListener({
  sessionUrlChangedCallback: urlChangedCallback 
});
```