Repository navigation
fix: put the pixel's data attributes on its own script tag - #3
Merged
Merged
Conversation
The script_loader_tag filter receives the inline bootstrap printed before the pixel as well as the pixel tag, and add_attributes() stamped the first <script it found. The site key and every other data-* attribute landed on the inline bootstrap, the pixel read its own tag through document.currentScript, found no site key, and sent nothing. Target the tag whose id is linkforty-pixel-js (single-quoted on WordPress 6.3, double-quoted from 6.4), falling back to the first tag with a src when an optimization plugin has rewritten the id.
|
🎉 This PR is included in version 0.2.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On 0.2.0 the pixel sends no events at all. The page source looks right at a glance, but the attributes are on the wrong tag:
script_loader_tagreceives the whole tag string for the handle, and that includes the inlinebeforescript added bywp_add_inline_script()(WP_Scripts::do_item()builds$translations . $before_script . <script src>).add_attributes()replaced the first<script, which is the bootstrap. The pixel reads its config fromdocument.currentScript(its ownsrctag), finds nodata-workspace, and stays silent — no console error, andwindow.LinkFortyis still defined.Fix
LinkForty_Pixel::add_attributes()now targets the tag withid="linkforty-pixel-js", matching either quote style (WordPress 6.3 printsid='…'viaprintf; 6.4+ useswp_get_script_tag()with double quotes). If an optimization plugin has rewritten the id, it falls back to the first tag with asrc. If neither matches, the tag is returned unchanged.wp_script_attributeswould be cleaner but is not applied to enqueued scripts on 6.3, which the plugin still supports.Verification
wp_print_head_scripts()output:add_attributes()was run against the exact string 6.3 prints): attributes land on thesrctag. Also checked: a tag with no id (fallback tosrc), and another handle (untouched).composer lintandcomposer phpcspass.Sites already on 0.2.0 are also covered from the pixel side: the pixel now falls back to any
script[data-workspace]when its own tag has none. This release removes the dependence on that fallback.