Add onSessionChangeCallback to react-native tracker#1436
Add onSessionChangeCallback to react-native tracker#1436Dmytro Nedolia (dnedo) wants to merge 2 commits intosnowplow:masterfrom
Conversation
…onfiguration and update related session handling logic
|
Thanks for your pull request. Is this your first contribution to a Snowplow open source project? Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://docs.snowplowanalytics.com/docs/contributing/contributor-license-agreement/ to learn more and sign. Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks. |
|
This looks great, thank you for the contribution! Can I please ask you to add a unit test in the it('calls onSessionUpdateCallback when a new session starts', async () => {
jest.setSystemTime(new Date('2022-04-17T00:00:00.000Z'));
const callback = jest.fn();
const sessionPlugin = await newSessionPlugin({
asyncStorage: AsyncStorage,
namespace: 'test-callback',
foregroundSessionTimeout: 5,
backgroundSessionTimeout: 5,
onSessionUpdateCallback: callback,
});
const tracker = trackerCore({ corePlugins: [sessionPlugin.plugin] });
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
expect(callback).toHaveBeenCalledTimes(1);
const initialState = await sessionPlugin.getSessionState();
expect(callback).toHaveBeenCalledWith(expect.objectContaining({
sessionId: initialState.sessionId,
}));
// Advance time to force session timeout
jest.setSystemTime(new Date('2022-04-17T00:00:10.000Z'));
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
expect(callback).toHaveBeenCalledTimes(2);
const updatedState = await sessionPlugin.getSessionState();
expect(callback).toHaveBeenCalledWith(expect.objectContaining({
sessionId: updatedState.sessionId,
}));
expect(initialState.sessionId).not.toEqual(updatedState.sessionId);
});About the |
|
Also please sign the CLA in order for us to be able to integrate this, thanks! |
This PR resolves #1432 by adding the ability to pass an onSessionUpdateCallback callback to the react-native tracker.
This has worked for our team when used as a patch. However, please let me know if there are any further changes required to get this merged into the library. For example, it looks like the session plugin exposes the startNewSession method, which as far as I can tell is not called anywhere right now. Perhaps the team has additional context or future plans that would require adjusting the implementation to account for sessions updated this way?