Problem/Motivation
The opt-in dialog does not appear unless the page is manually refreshed. This happens because the Google API script loads asynchronously after the Drupal behavior runs.
Steps to reproduce
- Configure the module with a valid Merchant ID;
- Enable the Google Customer Reviews pane on the checkout complete step (default configuration);
- Complete a checkout;
- Observe that the opt-in dialog does not appear on the complete page;
- Refresh the page => the dialog now appears.
Proposed resolution
Two issues prevent the dialog from showing:
Incorrect onload handler
In google_customer_reviews.libraries.yml, the onload attribute uses onload: renderOptIn which only references the function but does not call it. It should be onload: "renderOptIn()".
Remaining tasks
- Review and test the patch
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | optin-dialog-fix-3571687-2.patch | 570 bytes | oana.hulpoi |
| optin-dialog-fix.patch | 1.42 KB | oana.hulpoi |
Issue fork google_customer_reviews-3571687
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
oana.hulpoi commentedComment #3
oana.hulpoi commentedAfter further investigation, the root cause is simpler than initially described. The issue is only in the library definition.
The original
google_customer_reviews.libraries.ymluses an HTMLonloadattribute:https://apis.google.com/js/platform.js: { type: external, attributes: { async: true, defer: true, onload: renderOptIn } }This references the function but doesn't reliably call it after the API is fully initialized.
Google's documentation specifies using the
?onloadquery parameter on the script URL:https://apis.google.com/js/platform.js?onload=renderOptIn: { type: external, attributes: { async: true, defer: true } }This is Google's own callback mechanism built into
platform.js. It callsrenderOptIn()after the API is fully initialized.No changes needed to the JS file. Updated patch attached with the one-line YAML fix.
Comment #5
rhovlandThank you for reporting this. I tested the module and have had it in production for a while now but missed this. I'm curious what browser did you encounter this in.
From my research it appears that the way I wrote this library file puts the onload as an HTML attribute which I guess sometimes fails to trigger in some browsers?
You're definitely right that google expects it in the url. I didn't know there was a difference.
Comment #7
rhovland