Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for on new session start callback #455

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

kevinpagtakhan
Copy link
Contributor

@kevinpagtakhan kevinpagtakhan commented Nov 29, 2021

Summary

This PR adds support for on new session start callback. Callback functions can be registered to onNewSessionStart event using the following ways:

Method 1

amplitude.getInstance().onNewSessionStart(() => {
  console.log('new session - method 1');
});

Method 2

amplitude.init('API_KEY', USER_ID, {
  onNewSessionStart: () => {
    console.log('new session - method 2')
  },
});

Testing

  • Unit tests are passing
  • Manually tested by executing the following below:
// cookies are deleted and page is refreshed

// register onInit callback
> amplitude.getInstance().onInit(() => console.log('init'))

// register session callback 1
> amplitude.getInstance().onNewSessionStart(() => console.log('session - method 1'))

// register session callback 2
// invoke init - runs registered callback fns
> amplitude.init('a2dbce0e18dfe5f8e74493843ff5c053', undefined, { onNewSessionStart: () => console.log('session - method 2') })
init
session - method 1
session - method 2

// invoke init - does not run registered callbacks fns
// init callback is already reset
// session callbacks are not called because no new session is created
> amplitude.init('a2dbce0e18dfe5f8e74493843ff5c053')

// invoke setUserId and create new session  - runs registered callback fns
> amplitude.getInstance().setUserId('asdf', true)
session - method 1
session - method 2

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change? None

Closes #429

Copy link
Contributor

@jooohhn jooohhn left a comment

Choose a reason for hiding this comment

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

LGTM!

@kevinpagtakhan kevinpagtakhan merged commit acf596a into main Nov 30, 2021
@kevinpagtakhan kevinpagtakhan deleted the AMP-45559-on-new-session-start-cb branch November 30, 2021 01:08
github-actions bot pushed a commit that referenced this pull request Nov 30, 2021
# [8.13.0](v8.12.0...v8.13.0) (2021-11-30)

### Bug Fixes

* add public method onNewSessionStart to snippet ([#459](#459)) ([07446fc](07446fc))
* upgrade to @amplitude/[email protected] ([#456](#456)) ([8962604](8962604))

### Features

* add support for on new session start callback ([#455](#455)) ([acf596a](acf596a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On new session start callback
2 participants