Background, using NextJS and trying to log events to Amplitude with dynamically generated eventKeys. I asked a similar question about access Page fields in databindings and that’s been hugely helpful.
But I’m running into an issue today where I have a button in a symbol and in the onClick event, I’m trying to extract the Screen Name (Page Level Field) in order to build the event key. The issue is that it appears that Symbols don’t have page fields available in
context.builderContent, only the Symbol levels fields. Is there anyway to force the page’s builderContent into the Symbol context?
FWIW, I recognize that this is probably the edgiest of edge cases, but it feels like Symbols kind of restrict what you can do with the data coming back from Builder.
Have you enabled
Inherit state under the Advanced settings for symbols, which allows inheriting the parent component state and data to symbols?
Once again @manish-sharma , you save the day! I didn’t even know that was a setting. I’ll flip it on for the symbols I’m tracking and see if it works. Thanks!
Well, I thought that would fix it, but even after turning the switch on for my symbols, I’m not getting the parent state passed through to my code.
Is that only accessible in the Visual Editor? I mean, I figure if builderState has that data in the editor, it would make sense for it be passed down in the builderState prop that is exposed to components, wouldn’t it?
EDIT: I think I realize the disconnect here. I’m not trying to pass the page field into the symbol itself for consumption there. I’m trying to extract the page field from the
builderState property in my custom component code so that I can use it to concatenate an event key. So, what you showed is that a symbol has access to the page field internally, but it doesn’t seem to get passed through in the
builderState prop I have access to in my custom component (that is a component inside of a symbol).
@manish-sharma Thanks for sharing that link. We’ve already integrated the data coming from Builder in our components, so it’s not an issue with that. It’s just an issue with the
builderState prop coming from Symbols not having all of the page context available in it. I’m going to check again and just make sure that with the Inherit state switch on I’m still not getting the fully populated
builderState, but as of this morning, even with the switch on, I was only getting the context of the Symbol, not the containing/parent page.