Event provider JS doesn't load on production build
Bug Description
The event provider JS loaded on the front end for its respective supported plugin integration for enhanced conversion tracking does not load when using a production build of Site Kit. It does work on development builds, but not intentionally.
Steps to reproduce
- Use a production build of SK
- Setup GA and enable enhanced conversion tracking
- Enable a supported plugin
- View frontend
- See 404 for event provider JS
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Event provider JS should load as expected regardless of the type of build used
- Generated provider JS filenames should have a
googlesitekit-events-provider-prefix for consistency
Implementation Brief
- [ ] Within the Conversion Events WebPack config file at
webpack/conversionEventProviders.config.js:- [ ] Prepend the file names in the
entryobject with'googlesitekit-events-provider-', i.e'googlesitekit-events-provider-contact-form-7': './assets/js/event-providers/contact-form-7.js',
- [ ] Prepend the file names in the
- [ ] For each of the event provider classes within the
includes/Core/Conversion_Tracking/Conversion_Event_Providersfolder, undertake the following changes:- [ ] Replace the prepended
'gsk-cep-'string from the handle passed toScript()with the string value prepended to filenames in the webpack config,'googlesitekit-events-provider-'. This will ensure correct resolving of the script src by theScriptclass, regardless of production or development modes. - [ ] Leave the
srcentry of theScript()args unchanged.
- [ ] Replace the prepended
Test Coverage
- This feature requires no updates to existing test suites
QA Brief
- Set up Site Kit with Analytics and Enhanced Conversion Tracking enabled.
- Install plugins that have enhanced tracking event support (Contact Form 7, WooCommerce, for example)
- Visit the site homepage
- Confirm the event provider
.jsfiles now load correctly by viewing page source and searching forgooglesitekit-events-provider-contact-form-7-$HASH.js
Changelog entry
- Fix bug that prevented Event Provider JavaScript files from loading.
@10upsimon I actually had a similar issue on my Consent Mode refactor issue #8384 today, this is how I fixed it.
IB ✅
@tofumatt @10upsimon @benbowler
- change the logic within the
register_script()method to instead use theManifest::get()method, passingself::CONVERSION_EVENT_PROVIDER_SLUGas the parameter, to obtain the filename
This would work but isn't necessary as Script already handles the application of the file in the Manifest automatically. Ultimately, this is the root cause for the issue as you'll notice no assets touch the Manifest directly yet they all load the right URLs for the build. We simply need to update the event provider scripts to follow the same approach as every other asset rather than treating these as a special case unnecessarily.
Thanks @aaemnnosttv I've simplified this and handed back to you.
- For each of the event providers within the
includes/Core/Conversion_Tracking/Conversion_Event_Providersfolder, change the logic within theregister_script()method to instead pass just theself::CONVERSION_EVENT_PROVIDER_SLUGconstso as to handle correctManifestbehavior when surfacing the asset URL- Remove the prepended
'gsk-cep-'string from the handle passed toScript(), this will ensure correct handling of the Manifest entry in theScriptclass.
@10upsimon while this will have the intended outcome as far as loading the script is concerned, it's changing the handle to be generic. E.g. gsk-cep-mailchimp will become mailchimp, which as a (global) WP script handle, is not something SK should be using but this might not be obvious due to the abstraction of our Script; it does not add any kind of namespacing, etc to the given handle. With that said, we should update both the handle and the entry name (key) to reference the same value (according to the AC) since the entry name is what the resulting manifest is keyed by.
Since the entry name also defines the default resulting filename, there's no need to add the prefix to the output if it's included in the entry name.
IB ✅
QA Update ✅
- Tested on dev environment.
- Verified event tracking for
WooCommerceandWPFormsplugin. - Verified now event are getting track using tester plugin.
- Verified the event provider .js files now load correctly by viewing page source and searching for
googlesitekit-events-provider-contact-form-7-$HASH.js - Verified JS filenames have a googlesitekit-events-provider- prefix for consistency.
JS files
WPFORMS
When only Analytics is connected
When both analytics and Ads module connected
https://github.com/google/site-kit-wp/assets/94359491/75588f69-512a-420f-aee3-da18d52d2048
Woocommerce
https://github.com/google/site-kit-wp/assets/94359491/4f016f17-81bb-4a9a-9ed7-34f7ea44b6e3
event : add to cart
When only analytics is connected
Both analytics and Ads module connected
event : Purchase
When both analytics and Ads module connected