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

Move in-page script to tracker.js #73

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

jhonatan-lopes
Copy link
Collaborator

Move the window.wagtailAbTesting in-page script to tracker.js. This will allow for a better CSP control as we move away from in-line scripts.

In addition, the logic to get the parameters necessary for tracking has been offloaded from the script to the template tag function.

Finally, the data is now passed to tracker.js via the json_script built-in Django template filter, which takes care of JS escaping and is compatible with a strict CSP.

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 88.40%. Comparing base (54f244c) to head (162e707).

Files Patch % Lines
...ab_testing/templatetags/wagtail_ab_testing_tags.py 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   87.84%   88.40%   +0.55%     
==========================================
  Files          15       15              
  Lines         732      750      +18     
  Branches      137      140       +3     
==========================================
+ Hits          643      663      +20     
+ Misses         54       51       -3     
- Partials       35       36       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerolab zerolab changed the title Move in-page script to tacker.js Move in-page script to tracker.js Feb 23, 2024
Copy link
Member

@Stormheg Stormheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing – thank you so much @jhonatan-lopes! ❤️

Quick question: is this the only change we need to make to be CSP compatible? If it is, I'd say we can advertise CSP compatibility in the readme!

@jhonatan-lopes
Copy link
Collaborator Author

I think this should be enough to make it CSP compatible. Yep, advertising it in the README sounds like a great idea

@jhonatan-lopes jhonatan-lopes merged commit e42afe9 into main Mar 20, 2024
11 checks passed
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

Successfully merging this pull request may close these issues.

2 participants