Smart Links: Add functionality context to ITM parameters#3216
Smart Links: Add functionality context to ITM parameters#3216acicovic merged 6 commits intoadd/traffic-boostfrom
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new protected property Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Endpoint
participant SmartLink
Client->>Endpoint: Request smart link creation
Endpoint->>SmartLink: Instantiate Smart_Link & call load()
SmartLink-->>Endpoint: Return smart link data (context may be null)
alt Context not set
Endpoint->>SmartLink: set_context("smart_linking")
end
SmartLink->>SmartLink: Process save() / get_link_href() with context
Endpoint->>Client: Return smart link details with updated ITM parameters
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)`**/*.{html,php}`: "Perform a detailed review of the provided code with following key aspects in mind: - Review the HTML and PHP code to ensure it is well-structured and adheres ...
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (9)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Models/class-smart-link.php (1)
698-707: Consider adding validation for the context value.While the
set_contextmethod is well-implemented, consider adding validation to ensure the context is one of the expected values (e.g., 'traffic_boost' or 'smart_linking').public function set_context( string $context ): void { + $valid_contexts = array( 'traffic_boost', 'smart_linking' ); + if ( ! in_array( $context, $valid_contexts, true ) ) { + _doing_it_wrong( __METHOD__, sprintf( 'Invalid context: %s. Valid contexts are: %s.', esc_html( $context ), implode( ', ', $valid_contexts ) ), '3.18.0' ); + } $this->context = $context; }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
build/content-helper/editor-sidebar.asset.phpis excluded by!build/**build/content-helper/editor-sidebar.jsis excluded by!build/**
📒 Files selected for processing (5)
src/Models/class-smart-link.php(6 hunks)src/content-helper/editor-sidebar/smart-linking/utils.ts(1 hunks)src/rest-api/content-helper/class-endpoint-smart-linking.php(3 hunks)src/rest-api/content-helper/class-endpoint-traffic-boost.php(3 hunks)tests/Integration/RestAPI/ContentHelper/EndpointSmartLinkingTest.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{html,php}`: "Perform a detailed review of the provided code with following key aspects in mind: - Review the HTML and PHP code to ensure it is well-structured and adheres ...
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/rest-api/content-helper/class-endpoint-traffic-boost.phptests/Integration/RestAPI/ContentHelper/EndpointSmartLinkingTest.phpsrc/rest-api/content-helper/class-endpoint-smart-linking.phpsrc/Models/class-smart-link.php
`**/*.{js,ts,tsx,jsx}`: "Perform a detailed review of the provided code with following key aspects in mind: - Review the code to ensure it is well-structured and adheres to best ...
**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the code to ensure it is well-structured and adheres to best practices.
- Verify compliance with WordPress coding standards.
- Ensure the code is well-documented.
- Check for security vulnerabilities and confirm the code is secure.
- Optimize the code for performance, removing any unnecessary elements.
- Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
- Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/smart-linking/utils.ts
🧬 Code Definitions (3)
src/rest-api/content-helper/class-endpoint-traffic-boost.php (2)
src/Models/class-smart-link.php (2) (2)
set_context(705-707)get_context(491-493)src/rest-api/content-helper/class-endpoint-smart-linking.php (1) (1)
get_pch_feature_name(75-77)
src/rest-api/content-helper/class-endpoint-smart-linking.php (2)
src/Models/class-smart-link.php (2) (2)
set_context(705-707)get_context(491-493)src/rest-api/content-helper/class-endpoint-traffic-boost.php (1) (1)
get_pch_feature_name(74-76)
src/Models/class-smart-link.php (1)
src/Utils/class-utils.php (2) (2)
Utils(34-498)append_itm_params(479-497)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: E2E against WordPress latest
🔇 Additional comments (15)
tests/Integration/RestAPI/ContentHelper/EndpointSmartLinkingTest.php (2)
314-316: Assertion updates match the new ITM parameter structure.The assertions have been correctly updated to verify the new ITM parameter values, reflecting the changes to the smart link context implementation. This ensures the tests validate that links include the updated campaign, medium, and source values.
447-449: Updated assertions ensure consistency across multiple test cases.These assertions correctly mirror the updates made in the first test method, ensuring consistent validation of ITM parameters across different test scenarios.
src/content-helper/editor-sidebar/smart-linking/utils.ts (1)
764-768: Updated ITM parameter values to improve tracking clarity.The changes to the
addSmartLinkITMParamsToURLfunction properly implement the updated parameter values:
- Updated
campaignfrom 'parsely-pch' to 'wp-parsely' for better brand alignment- Added new
mediumparameter with value 'smart-link' for clearer categorization- Changed
sourcefrom 'smart-link' to 'smart-linking' to differentiate from Traffic BoostThese changes improve tracking granularity by distinguishing between different content distribution mechanisms.
src/rest-api/content-helper/class-endpoint-traffic-boost.php (3)
388-390: Added context for link tracking in Traffic Boost.This change sets the appropriate context for smart links generated through the Traffic Boost feature, ensuring they can be properly identified in analytics. The context is set from the feature name, providing consistency across the plugin.
522-524: Added context for placement suggestions.Similar to the previous change, this addition ensures that valid placement suggestions also receive the proper Traffic Boost context, maintaining consistency in how smart links are tracked.
859-862: Added fallback context for smart links.This conditional check ensures that any smart link that doesn't already have a context is assigned the Traffic Boost context. It's a good defensive measure that maintains backward compatibility while ensuring all smart links processed through this endpoint have appropriate context information.
src/rest-api/content-helper/class-endpoint-smart-linking.php (3)
252-254: Added context for smart links generated via Smart Linking.Sets the context for smart links to indicate they were created through the Smart Linking feature. This is important for proper tracking and distinguishing links from different sources in analytics.
327-330: Added fallback context for added smart links.This conditional check ensures that any smart link without a context gets properly tagged with the Smart Linking context. This helps maintain consistency in how links are tracked while respecting any context that might have been set elsewhere.
605-608: Added fallback context during smart link validation.Similar to the previous change, this ensures that smart links being validated also receive the appropriate context if one isn't already set. This provides a consistent approach to context handling across different endpoints and methods.
src/Models/class-smart-link.php (6)
42-50: LGTM: New context property is well-documented.The addition of the new protected property
$contextis well-documented with proper PHPDoc comments following WordPress coding standards. The property will be used to store context information like 'traffic_boost' or 'smart_linking'.
267-270: LGTM: Properly loading the context from post meta.This code correctly checks for the existence of the context in the smart link post meta and assigns it to the
$contextproperty if found.
372-374: LGTM: Properly saving the context to post meta.The context is only added to the post meta if it has a value other than
false, which prevents storing unnecessary data.
469-482: Improved ITM parameter handling.The changes replace hardcoded parameters with a more dynamic approach, allowing the context to be included as the 'source' parameter. This aligns with the PR objective to add functionality context to ITM parameters.
484-493: LGTM: Well-implemented getter method.The
get_contextmethod is properly implemented and documented.
742-742: LGTM: Properly including context in the serialized object.The context is correctly included in the array representation of the smart link.
…ontext # Conflicts: # build/content-helper/editor-sidebar.asset.php # build/content-helper/editor-sidebar.js # src/Models/class-smart-link.php
Co-authored-by: Alex Cicovic <23142906+acicovic@users.noreply.github.com>
|
@acicovic should be fixed now, not sure why that was introduced in the first place though. |
…arams-context Smart Links: Add functionality context to ITM parameters" (1338df1)
Description
This PR adds feature context to the Smart Links, so it's possible to determine where they have been created - either Smart Linking or Traffic Boost.
This context is used to fill the ITM parameters used to track views generated through Smart Links. The new context field is added as the ITM source. The ITM campaign and medium have also been changed to be more generic.
Motivation and context
Track how Smart Links are impacting the site's traffic and recirculation performance.
How has this been tested?
Tested locally and passing existing tests.
Summary by CodeRabbit
New Features
Tests