braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
70 stars 25 forks source link

[Bug]: Content Cards of old user are shown to new user #134

Closed psimk closed 1 year ago

psimk commented 1 year ago

Braze Web SDK Version

4.4.0

Integration Method

NPM

Browser

Chrome

Steps To Reproduce

Setup

I created a small React application using

npx create-react-app

Installed the Braze SDK

npm install @braze/web-sdk@4

And updated the App.js file to include:

import { changeUser, initialize, removeAllSubscriptions, requestPushPermission, subscribeToContentCardsUpdates } from '@braze/web-sdk'

function App() {
  return (
    <div className="App">
      <button onClick={async () => {
        try {
        removeAllSubscriptions()
        } catch {}

        initialize(
         '<insert-api-key>',
          {
            enableLogging: true,
            baseUrl: 'sdk.fra-01.braze.eu',
            enableSdkAuthentication: false,
          })

        requestPushPermission()
        subscribeToContentCardsUpdates(console.log)

        changeUser('repro-user-1')

      }}>use User 1</button>
      <button onClick={async () => {
        try {
        removeAllSubscriptions()
        } catch {}

        initialize(
         '<insert-api-key>',
          {
            enableLogging: true,
            baseUrl: 'sdk.fra-01.braze.eu',
            enableSdkAuthentication: false,
          })

        requestPushPermission()
        subscribeToContentCardsUpdates(console.log)

        changeUser('repro-user-2')
      }}>use User 2</button>
    </div>
  )
}

Actual Reproduction Steps

  1. Launch Reproduction Application
  2. Click "use User 1"
  3. Send out a test campaign for user repro-user-1
  4. Click the Notification for the test campaign (this should open the application)
  5. Click "use User 1"
  6. See the console log containing the test Content Card
  7. Click "use User 2"
  8. See the console log containing the test Content Card

Expected Behavior

I expected that the content card would be tied to the user I sent the content card for "repro-user-1". "repro-user-2" should not have received the content card.

Actual Incorrect Behavior

"repro-user-2" receives the same content card as "repro-user-1", even though it was sent only for "repro-user-1".

Verbose Logs

Braze: Initialization Options: {
  "enableLogging": true,
  "baseUrl": "sdk.fra-01.braze.eu",
  "enableSdkAuthentication": false
}
Braze: Initialized for the Braze backend at "sdk.fra-01.braze.eu" with API key "e4004bbf-ba1a-45ed-af6a-8bcbd936b026".
CONSOLE.LOG -> ContentCards {cards: Array(0), lastUpdated: null}
Braze: Generating session start event with time 1669196119544. Will expire 1669197919544
Braze: Invoking new session subscriptions
Braze: Changed user to "repro-user-1".
Braze: Trigger event open did not match any trigger conditions.
CONSOLE.LOG -> ContentCards {cards: Array(2), lastUpdated: Wed Nov 23 2022 11:35:19 GMT+0200 (Eastern European Standard Time)}
Braze: Device already subscribed to push, sending existing subscription to backend.
Braze: Braze has already been initialized with an API key.
CONSOLE.LOG -> ContentCards {cards: Array(0), lastUpdated: null}
Braze: Generating session start event with time 1669196124445. Will expire 1669197924445
Braze: Invoking new session subscriptions
Braze: Changed user to "repro-user-2".
Braze: Trigger event open did not match any trigger conditions.
CONSOLE.LOG -> ContentCards {cards: Array(2), lastUpdated: Wed Nov 23 2022 11:35:24 GMT+0200 (Eastern European Standard Time)}
Braze: Device already subscribed to push, sending existing subscription to backend.

Additional Information

No response

wesleyorbin commented 1 year ago

Hi @psimk. I followed your steps and was unable to reproduce. If you look at the third instance where it prints out content cards, you can see that it is actually erasing the content cards as you change user. I recommend that you send an email to support@braze.com with this information along with links to any relevant campaigns. I'd also recommend that you print out the cards contained within the content cards object so our support team can see which cards are being sent to both users.