-
-
Notifications
You must be signed in to change notification settings - Fork 0
VjEgRazw/181: created a new behat feature for checking GA presence. #31
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
Conversation
WalkthroughA new Behat feature test file was added to verify the conditional injection of the Google Analytics 4 script on the homepage based on user authentication status. It tests that an anonymous user receives the GA4 script in the response, while a logged-in user with the "authenticated" role does not. Additionally, the Google Tag Manager configuration was updated to add a dependency on the "user" module, introduce a "user_role" condition for anonymous users, and reorder event definitions including adding placeholders for "search" and "custom" events. No exported or public code entities were changed. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WebApp
participant GoogleTagManager
User->>WebApp: Visit homepage (anonymous)
WebApp-->>User: Serve homepage HTML (includes GA4 script)
User->>GoogleTagManager: (Script loads) Request gtag.js
GoogleTagManager-->>User: Serve gtag.js
Note over User,WebApp: For authenticated users:
User->>WebApp: Visit homepage (authenticated)
WebApp-->>User: Serve homepage HTML (no GA4 script)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
tests/behat/features/tracking.feature (1)
10-11:⚠️ Potential issueFix syntax error: missing trailing quote
There appears to be a syntax error at the end of the file - the last line is missing a closing double quote.
- And the response should contain "https://www.googletagmanager.com/gtag/js?id=G-" + And the response should contain "https://www.googletagmanager.com/gtag/js?id=G-" 11
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (1)
tests/behat/features/tracking.feature(1 hunks)
🔇 Additional comments (1)
tests/behat/features/tracking.feature (1)
1-5: Feature declaration looks good!The feature is clearly defined with appropriate tags and follows the standard user story format.
| @api @javascript | ||
| Scenario: Check Google Analytics 4 script on homepage | ||
| Given I am an anonymous user | ||
| When I am on the homepage | ||
| And the response should contain "https://www.googletagmanager.com/gtag/js?id=G-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Good implementation of the GA4 tracking check
The scenario correctly verifies the presence of the Google Analytics 4 script on the homepage. Some considerations for future enhancements:
- You might want to check for the complete tracking ID if it's known (e.g., "G-XXXXXXXXXX") rather than just the URL prefix.
- If GA tracking should be present site-wide, consider adding tests for other important pages.
- For more comprehensive testing, you could verify the proper initialization of GA4 (checking for the gtag function or data layer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that tag is not set for logged in users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexSkrypnyk Here's a test scenario that verifies the Google Analytics tag is not set for logged-in users:
@api @javascript
Scenario: Google Analytics 4 script should not be present for logged in users
Given I am logged in as a user with the "authenticated" role
When I am on the homepage
Then the response should not contain "https://www.googletagmanager.com/gtag/js?id=G-"You can add this scenario to the existing tracking.feature file right after the anonymous user test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsineok ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
| As a site user | ||
| I want to ensure Google Analytics script is present on the page | ||
|
|
||
| @api @javascript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsineok does this need to be a JS test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexSkrypnyk, yes it does because GA script is injected via another JS file. modules/contrib/google_tag/js/gtag.js
| @api @javascript | ||
| Scenario: Check Google Analytics 4 script on homepage | ||
| Given I am an anonymous user | ||
| When I am on the homepage | ||
| And the response should contain "https://www.googletagmanager.com/gtag/js?id=G-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that tag is not set for logged in users
… GA container - GA works only for anonymous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (2)
config/default/google_tag.container.G-LCQ5CZ3H3W.680a169398dd50.88125398.yml(2 hunks)tests/behat/features/tracking.feature(1 hunks)
🔇 Additional comments (4)
config/default/google_tag.container.G-LCQ5CZ3H3W.680a169398dd50.88125398.yml (2)
4-6: Appropriate module dependency added.Good addition of the "user" module dependency, which is required for the user role condition implementation below.
15-22: Well-implemented user role condition.The condition properly targets anonymous users only, which aligns with privacy best practices by not tracking authenticated users. The context mapping is correctly configured to use the current user context.
tests/behat/features/tracking.feature (2)
6-10: Well-implemented test for anonymous users.This scenario correctly tests that the Google Analytics script is present for anonymous users. The @javascript tag is appropriate since the GA script is injected via JavaScript.
12-16: Correctly implemented test for authenticated users.This scenario properly verifies that the Google Analytics script is not present for authenticated users, as requested in the previous review comments. This is an important privacy consideration and complements the first test case.
| search: { } | ||
| custom: { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Empty placeholder events added.
The "search" and "custom" empty event placeholders have been added. Consider adding a comment about their intended future use or create tickets to implement these events if they're needed.
| @tracking @google | ||
| Feature: Google Analytics is injected | ||
| As a site user | ||
| I want to ensure Google Analytics script is present on the page | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Well-structured feature description.
The feature is properly tagged and includes a clear description of the functionality being tested. Consider enhancing the description to mention the conditional nature of the tracking (i.e., only for anonymous users).
@tracking @google
Feature: Google Analytics is injected
As a site user
- I want to ensure Google Analytics script is present on the page
+ I want to ensure Google Analytics script is present for anonymous users and absent for authenticated users📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| @tracking @google | |
| Feature: Google Analytics is injected | |
| As a site user | |
| I want to ensure Google Analytics script is present on the page | |
| @tracking @google | |
| Feature: Google Analytics is injected | |
| As a site user | |
| I want to ensure Google Analytics script is present for anonymous users and absent for authenticated users |
Checklist before requesting a review
[#123] Verb in past tense.#123added to descriptionChangedsectionChanged
Screenshots
Summary by CodeRabbit