mirceapiturca / Sections

Shopify sections for everyone. Tooltips, FAQ, Quiz, and App Performance
https://sections.design
MIT License
173 stars 80 forks source link

Facebook Pixel script and others not loading #29

Open Tanisyr opened 1 month ago

Tanisyr commented 1 month ago

Even though your code seems like it should be passing through any script not explicitly blocked in its settings, the app is effectively blocking other scripts that are being created dynamically. I have tried debugging this myself but to no avail. In particular there seems to be an issue in the modifyCreateElement function that is causing normal document.createElement('script') tags to not have their src attribute loaded properly. Have you encountered this before?

When I disable the app optimization my Facebook Pixel sales channel script executes properly again. I would like to be able to use both, please advise.

To reproduce, create a store with the Facebook & Instagram sales channel connected with a Facebook pixel and any other plugin to be optimized. Add the app optimization code and configure it to block the other plugin on the homepage. Using the Facebook Pixel Debugger observe how the pixel code is working on every page but the homepage.

Tanisyr commented 1 month ago

I found my issue. For some reason some of the Shopify code was passing a src attribute that was not a string, but an instance of TrustedScriptURL, which doesn't contain an indexOf method. This was causing your url comparison logic to error out and prevent the src attribute from being set correctly on certain script.

The fix is to change the line:

return stringIncludes(src, item.url);

to

return stringIncludes(src.toString(), item.url);