Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,17 @@ public void onInboxUpdated() {

// ---------------------------------------------------------------------------------------
// region Embedded messaging

public void startEmbeddedSession() {
IterableLogger.d(TAG, "startEmbeddedSession");
IterableApi.getInstance().getEmbeddedManager().getEmbeddedSessionManager().startSession();
}

public void endEmbeddedSession() {
IterableLogger.d(TAG, "endEmbeddedSession");
IterableApi.getInstance().getEmbeddedManager().getEmbeddedSessionManager().endSession();
}

public void getEmbeddedPlacementIds(Promise promise) {
IterableLogger.d(TAG, "getEmbeddedPlacementIds");
try {
Expand Down
10 changes: 10 additions & 0 deletions android/src/newarch/java/com/RNIterableAPIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ public void pauseAuthRetries(boolean pauseRetry) {
moduleImpl.pauseAuthRetries(pauseRetry);
}

@Override
public void startEmbeddedSession() {
moduleImpl.startEmbeddedSession();
}

@Override
public void endEmbeddedSession() {
moduleImpl.endEmbeddedSession();
}

@Override
public void getEmbeddedPlacementIds(Promise promise) {
moduleImpl.getEmbeddedPlacementIds(promise);
Expand Down
10 changes: 10 additions & 0 deletions android/src/oldarch/java/com/RNIterableAPIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ public void pauseAuthRetries(boolean pauseRetry) {
moduleImpl.pauseAuthRetries(pauseRetry);
}

@ReactMethod
public void startEmbeddedSession() {
moduleImpl.startEmbeddedSession();
}

@ReactMethod
public void endEmbeddedSession() {
moduleImpl.endEmbeddedSession();
}

@ReactMethod
public void getEmbeddedPlacementIds(Promise promise) {
moduleImpl.getEmbeddedPlacementIds(promise);
Expand Down
20 changes: 20 additions & 0 deletions example/src/components/Embedded/Embedded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export const Embedded = () => {
});
}, []);

const startEmbeddedSession = useCallback(() => {
console.log(
'startEmbeddedSession --> check android/ios logs to check if it worked'
);
Iterable.embeddedManager.startSession();
}, []);

const endEmbeddedSession = useCallback(() => {
console.log(
'endEmbeddedSession --> check android/ios logs to check if it worked'
);
Iterable.embeddedManager.endSession();
}, []);

return (
<SafeAreaView style={styles.container}>
<Text style={styles.text}>EMBEDDED</Text>
Expand All @@ -30,6 +44,12 @@ export const Embedded = () => {
<TouchableOpacity style={styles.button} onPress={getPlacementIds}>
<Text style={styles.buttonText}>Get placement ids</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={startEmbeddedSession}>
<Text style={styles.buttonText}>Start embedded session</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={endEmbeddedSession}>
<Text style={styles.buttonText}>End embedded session</Text>
</TouchableOpacity>
</SafeAreaView>
);
};
Expand Down
12 changes: 9 additions & 3 deletions example/src/hooks/useIterableApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const IterableAppProvider: FunctionComponent<
return jwtToken;
}, [userId]);

const login = useCallback(() => {
const login = useCallback(async () => {
const id = userId ?? process.env.ITBL_ID;

if (!id) return Promise.reject('No User ID or Email set');
Expand All @@ -134,12 +134,18 @@ export const IterableAppProvider: FunctionComponent<

const fn = getIsEmail(id) ? Iterable.setEmail : Iterable.setUserId;

fn(id);
let token;

if (process.env.ITBL_IS_JWT_ENABLED === 'true' && process.env.ITBL_JWT_SECRET) {
token = await getJwtToken();
}

fn(id, token);
Comment on lines +137 to +143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JWT related things can be made a separate PR if it needs attention outside scope of Embedded Messaging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second that!

setIsLoggedIn(true);
setLoginInProgress(false);

return Promise.resolve(true);
}, [userId]);
}, [getJwtToken, userId]);

const initialize = useCallback(
(navigation: Navigation) => {
Expand Down
8 changes: 8 additions & 0 deletions src/__mocks__/MockRNIterableAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export class MockRNIterableAPI {

static updateVisibleRows = jest.fn();

static startEmbeddedSession = jest.fn();

static endEmbeddedSession = jest.fn();

static getEmbeddedPlacementIds = jest
.fn()
.mockResolvedValue([1, 2, 3] as number[]);

// set messages function is to set the messages static property
// this is for testing purposes only
static setMessages(messages: IterableInAppMessage[]): void {
Expand Down
2 changes: 2 additions & 0 deletions src/api/NativeRNIterableAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export interface Spec extends TurboModule {
pauseAuthRetries(pauseRetry: boolean): void;

// Embedded Messaging
startEmbeddedSession(): void;
endEmbeddedSession(): void;
getEmbeddedPlacementIds(): Promise<number[]>;

// Wake app -- android only
Expand Down
16 changes: 16 additions & 0 deletions src/core/classes/IterableApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,22 @@ export class IterableApi {
// ======================= EMBEDDED ===================== //
// ====================================================== //

/**
* Starts an embedded session.
*/
static startEmbeddedSession() {
IterableLogger.log('startEmbeddedSession');
return RNIterableAPI.startEmbeddedSession();
}

/**
* Ends an embedded session.
*/
static endEmbeddedSession() {
IterableLogger.log('endEmbeddedSession');
return RNIterableAPI.endEmbeddedSession();
}

/**
* Get the embedded placement IDs.
*/
Expand Down
43 changes: 43 additions & 0 deletions src/embedded/classes/IterableEmbeddedManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { MockRNIterableAPI } from '../../__mocks__/MockRNIterableAPI';
import { IterableEmbeddedManager } from './IterableEmbeddedManager';

// Mock the RNIterableAPI module
jest.mock('../../api', () => ({
__esModule: true,
default: MockRNIterableAPI,
}));

describe('IterableEmbeddedManager', () => {
let embeddedManager: IterableEmbeddedManager;

beforeEach(() => {
embeddedManager = new IterableEmbeddedManager();
jest.clearAllMocks();
});

describe('isEnabled', () => {
Expand Down Expand Up @@ -55,5 +63,40 @@ describe('IterableEmbeddedManager', () => {
expect(embeddedManager.isEnabled).toBe(false);
});
});

describe('getPlacementIds', () => {
it('should call IterableApi.getEmbeddedPlacementIds', async () => {
// WHEN getPlacementIds is called
const result = await embeddedManager.getPlacementIds();

// THEN IterableApi.getEmbeddedPlacementIds is called
expect(MockRNIterableAPI.getEmbeddedPlacementIds).toHaveBeenCalledTimes(
1
);

// AND the result is returned
expect(result).toEqual([1, 2, 3]);
});
});

describe('startSession', () => {
it('should call IterableApi.startEmbeddedSession', () => {
// WHEN startSession is called
embeddedManager.startSession();

// THEN IterableApi.startEmbeddedSession is called
expect(MockRNIterableAPI.startEmbeddedSession).toHaveBeenCalledTimes(1);
});
});

describe('endSession', () => {
it('should call IterableApi.endEmbeddedSession', () => {
// WHEN endSession is called
embeddedManager.endSession();

// THEN IterableApi.endEmbeddedSession is called
expect(MockRNIterableAPI.endEmbeddedSession).toHaveBeenCalledTimes(1);
});
});
});

40 changes: 40 additions & 0 deletions src/embedded/classes/IterableEmbeddedManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { IterableApi } from '../../core/classes/IterableApi';
export class IterableEmbeddedManager {
/**
* Whether the embedded manager is enabled.
*
* This is set through the `enableEmbeddedMessaging` flag in the
* `IterableConfig` class.
*/
private _isEnabled = false;

Expand Down Expand Up @@ -41,4 +44,41 @@ export class IterableEmbeddedManager {
getPlacementIds() {
return IterableApi.getEmbeddedPlacementIds();
}

/**
* Starts a session.
*
* As session is a period of time when a user is on a screen or page that can
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in documentation: "As session" should be "A session".

Suggested change
* As session is a period of time when a user is on a screen or page that can
* A session is a period of time when a user is on a screen or page that can

Copilot uses AI. Check for mistakes.
* display embedded messages.
*
* When a user comes to a screen or page in your app where embedded messages
* are displayed (in one or more placements), a session should be started.
*
* @example
* ```typescript
* Iterable.embeddedManager.startSession();
* ```
*/
startSession() {
return IterableApi.startEmbeddedSession();
Comment on lines +60 to +63
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example shows static method call IterableEmbeddedManager.endSession(), but this should be an instance method call via Iterable.embeddedManager.endSession() to match the actual usage pattern in the SDK.

Copilot uses AI. Check for mistakes.
}

/**
* Ends a session.
*
* When a user leaves a screen in your app where embedded messages are
* displayed, the session should be ended. This causes the SDK to send
* session and impression data back to the server.
*
* A session is tracked when it is ended, so you should be able to find
* tracking data after this method is called.
*
* @example
* ```typescript
* Iterable.embeddedManager.endSession();
* ```
*/
endSession() {
return IterableApi.endEmbeddedSession();
}
}