braze-inc / braze-web-sdk

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

No cards received from appBoy.getCachedContentCards() in 2.4.x but works in 2.3.4 #62

Closed sukritchhabra closed 4 years ago

sukritchhabra commented 4 years ago

Setup

With 2.4.0 & 2.4.1

Changing to 2.3.4

Seems like just changing the version fixes the issue. Not sure if I missed something in the setup for 2.4.x that may be causing this.

froodian commented 4 years ago

Hi @sukritchhabra - sorry for the delay in responding.

If you open a console while this issue is occurring and call localStorage, do you see values in ab.storage.cc.[your-api-key]? What about ab.storage.ccDismissals.[your-api-key]?

Is there a staging instance where I can reproduce the issue to debug further? If you don't have or want to make something publicly available, you could raise this issue with our support team at https://www.braze.com/docs/support_contact in order to share those details privately (it'll come back to me if necessary).

sukritchhabra commented 4 years ago

@froodian No problem.

2.4.0 & 2.4.1 & 2.3.4

I do see info in localStorage.

If this ^ info doesn't help I can reach out to support and we can try and troubleshoot there :)

froodian commented 4 years ago

I wonder if you're simply running into a race condition where you're calling getCachedContentCards before the sync has completed. If you call it manually a second or two after the page finishes loading, do you see the cards you expect? In 2.4.x we did add functionality that requires the initial /api/v3/data call to complete (to retrieve configuration from the backend) before content cards can sync. If that's the case, I wonder if subscribeToContentCardsUpdates would be more appropriate to your use-case than getCachedContentCards?

sukritchhabra commented 4 years ago

Yup, tried subscribeToContentCardsUpdates with 2.4.1 and that worked 🎉 Thank you! :)

Out of curiosity, wondering if there's a way to listen (by the way of an async handler etc) for the finish of /data? Since seems like getCachedContentCards can lead to a race condition if triggered around the same time as the call to /data?

froodian commented 4 years ago

There is not a great way to do that currently, sorry - we have an item on our roadmap to introduce a completion callback to requestImmediateDataFlush which will be able to function for that purpose in the future.

Given that roadmap item, I'm going to close this issue since your use-case is now working for you, thanks!