braze-inc / braze-web-sdk

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

Segment initialised SDK more susceptible to race conditions #98

Closed justinsoong closed 3 years ago

justinsoong commented 3 years ago

Related to https://github.com/Appboy/appboy-web-sdk/issues/63

We use segment to initialise appboy, and are finding a small flurry of Appboy must be initialized before calling errors

Is there an event we can listen to to fire our appboy functions on initialisation complete?

Thanks

wesleyorbin commented 3 years ago

Hi @justinsoong! Thanks for reaching out. There is no event that fires upon initialization unfortunately. Could you provide any code samples that would help us debug in addition to the Braze Web SDK version that you're using?

justinsoong commented 3 years ago

@wesleyorbin we're using v2, not many code snippets but we're loading segment via google tag manager (https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/appboy/lib/index.js) this is loaded with the highest order in priority, followed by standard braze calls in lower order priority in GTM

This is happening more frequently because we can't identify when the appboy sdk is fully initialised as the segment initialisation of braze requires a network call to fetch the it's third party script loading configuration, which is likely the reason why this race condition is happening

davidbielik commented 3 years ago

Hi @justinsoong Can you please try using the v3.1 option in Segment? That SDK version contains an updated integration snippet which likely will help with the race condition you're describing.

If you still experience it on the v3.1 version, can you please raise a support ticket and our team can help dig into your specific website code and implementation?

justinsoong commented 3 years ago

Thank you @davidbielik are there any breaking changes, but I guess you'd point me to some docs if there were

davidbielik commented 3 years ago

Hi @justinsoong yes, you can view those here, but high level changes are:

  1. Segment will handle the change to the integration snippet.
  2. baseUrl is now required which you'd enter in Segment (if you're not already)
  3. Any custom javascript you have written that references appboy.ab and InAppMessage.Button will need to be updated

It should be a quick upgrade, but please review those docs in case you have custom javascript in your integration. Happy to help answer other questions as you upgrade!

justinsoong commented 3 years ago

@davidbielik we're still observing this in 3.1 albeit seems lesser based on our exception reporting

Screen Shot 2021-04-15 at 15 08 42
davidbielik commented 3 years ago

Hi @justinsoong thanks for confirming. Can you please open a support ticket (support@braze.com) to help dive in to your website's specific code and environment?

If you can please include more details around where else in your code are you referencing window.appboy outside of Segment, and other relevant code examples of when/where/how you're calling Braze methods, that'll be helpful.

wesleyorbin commented 3 years ago

@justinsoong We just released v3.3.0, which removes the loading snippet code from the npm package. This should fix any race conditions associated with your integration. I'm going to close out the issue for now, but if you continue to experience issues, feel free to re-open or contact our support team.

studiobrain commented 2 years ago

This seems to be the only place that is tracking this error.

current setup... Using Segment with Braze destination enabled and the following settings:

Screen Shot 2021-11-11 at 9 45 48 AM

There is currently no reference to window.analytics or window.appboy anywhere in the app however, as soon as the site loads:

Unhandled Runtime Error

Error: Appboy must be initialized before calling methods.
Call Stack
e
https://js.appboycdn.com/web-sdk/3.1/appboy.min.js (228:244)
Te
https://js.appboycdn.com/web-sdk/3.1/appboy.min.js (236:133)
$f
https://js.appboycdn.com/web-sdk/3.1/appboy.min.js (248:444)
<unknown>
https://js.appboycdn.com/web-sdk/3.1/appboy.min.js (262:102)
<unknown>
https://js.appboycdn.com/web-sdk/3.1/appboy.min.js (263:4)

There does not seem to be a way to update the sdk to 3.3 in this interface, are there any other options?

davidbielik commented 2 years ago

Hi @studiobrain can you please raise a ticket with our support team to help investigate specifics of your case?

gonbaum commented 2 years ago

Hi! We're having the same error:

Screenshot 2022-01-31 at 12 13 12

We're loading the SDK via Segment destination config as device mode. I can only select up to version 3.1 in segment's interface.

wesleyorbin commented 2 years ago

Hi @gonbaum. We are working with Segment to upgrade the SDK version in their interface. We'll update you here when that has been completed.

davidbielik commented 2 years ago

Hi @gonbaum @studiobrain @justinsoong our new Segment Braze Actions destination is now available which should let you upgrade to version 3.5 of our SDK.

https://segment.com/docs/connections/destinations/catalog/braze-web-device-mode-actions/

ciaranphillips-toast commented 2 years ago

@davidbielik - I'm hitting the same issue with a Tealium IQ integration rather than Segment, using web sdk 4.0.6. Is there still no way to identify when the Braze agent has been initialized? No flag or event?

EDIT: feeling a bit dumb here - waiting for document.readyState === 'complete' accomplishes what I need 😓 , as I just need the initialisation script from tealium to load first. Weirdly I think I haven't had to use that since jquery's .ready() 🤔

EDIT 2: I spoke to soon, this is still an issue :(