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

When it's not possible to run code during page-load, it's not possible to use this library #1223

Open
rgprog opened this issue Feb 5, 2025 · 1 comment

Comments

@rgprog
Copy link

rgprog commented Feb 5, 2025

From the documentation:

You can only call .load on page load, or reload (refresh). If you modify the .load method between page loads, it doesn’t have any effect until the page is reloaded.

I've been working on a Figma plugin. My plugin code runs in an iframe provided by the Figma web app. That iframe doesn't run any of my code until after its page has already loaded.

Segment hasn't received any tracking events which I generate in the Figma plugin. I think this is because my .load call is being queued until the next page refresh, and any .track calls are being queued until at least one .load call completes.

Is there a workaround for this problem?

@silesky
Copy link
Contributor

silesky commented Feb 10, 2025

Hey @rgprog, wish I could be more help

I assume there's some mechanism that figma plugins have that passes the analytics instance from the parent frame to the iframe? Best would be instantiate analytics within the iframe.

There's a lot to debug here -- if you aren't able to generate any segment events no matter what, I would assume there's some other error (make sure, in devtools, you're looking at the iframe console and not the js console). Make sure you're using the latest version the snippet as well.

Unfortunately, there's no one size fits all approach here.

I would recommending either having the snippet load completely within the iframe, or, if you're just looking to send a few basic segment events using fetch and can manage the user ID/anonId yourself, use the basic http api:

https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/

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

No branches or pull requests

2 participants