Skip to content

Smart Links: Add functionality context to ITM parameters#3216

Merged
acicovic merged 6 commits intoadd/traffic-boostfrom
update/smart-links-itm-params-context
Apr 4, 2025
Merged

Smart Links: Add functionality context to ITM parameters#3216
acicovic merged 6 commits intoadd/traffic-boostfrom
update/smart-links-itm-params-context

Conversation

@vaurdan
Copy link
Contributor

@vaurdan vaurdan commented Mar 21, 2025

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

    • Enhanced smart link functionality with a new context capability for improved tracking and categorization across various operations.
    • Updated URL parameters for accurate campaign and source identification, ensuring consistent tracking in link management.
  • Tests

    • Refined integration tests to validate the updated tracking parameters, reinforcing the reliability of smart link behavior.

@vaurdan vaurdan added Component: PHP Feature: PCI Ticket/PR related to Content Intelligence Feature: Engagement Boost Ticket/PR related to Engagement Boost labels Mar 21, 2025
@vaurdan vaurdan added this to the 3.18.0 milestone Mar 21, 2025
@vaurdan vaurdan self-assigned this Mar 21, 2025
@vaurdan vaurdan requested a review from a team as a code owner March 21, 2025 15:18
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

📝 Walkthrough

Walkthrough

This PR introduces a new protected property $context to the Smart_Link class along with getter and setter methods. The load, save, get_link_href, and to_array methods have been updated to incorporate this context. Additionally, related endpoint classes update their logic to assign a proper context when generating, adding, or validating smart links. URL parameter values in a utility function have been modified, and related tests have been updated to assert the new ITM parameter values.

Changes

File(s) Change Summary
src/Models/class-smart-link.php Added a protected $context property initialized to null, new public get_context and set_context methods, and updates to load, save, get_link_href, and to_array methods to support and propagate context.
src/content-helper/editor-sidebar/smart-linking/utils.ts Modified the URL parameter values: changed campaign from 'parsely-pch' to 'wp-parsely', updated source from 'smart-link' to 'smart-linking', and introduced a new parameter medium with the value 'smart-link'.
src/rest-api/content-helper/class-endpoint-smart-linking.php,
src/rest-api/content-helper/class-endpoint-traffic-boost.php
Updated endpoint methods (generate_smart_links, add_smart_link, validate_smart_link_params, generate_link_suggestions, generate_placement_suggestions, and validate_smart_link_id) to ensure that a proper context is set (e.g., "smart_linking" or "Traffic Boost") when processing smart links.
tests/Integration/RestAPI/ContentHelper/EndpointSmartLinkingTest.php Adjusted test assertions for ITM parameters: updated expected values for itm_campaign and itm_source, and added an assertion for itm_medium.

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
Loading

Possibly related PRs

  • PCH Smart Linking: Add Smart Linking back-end #2544: The changes in the main PR are related to those in the retrieved PR as both involve modifications to the Smart_Link class, specifically the addition of methods and properties that manage the context of smart links.
  • Traffic Boost: Fix permalinks and highlighting #3090: The changes in the main PR, which involve adding and managing a $context property in the Smart_Link class, are related to the modifications in the retrieved PR that also focus on updating how links are handled and ensuring consistent context management for smart links.
  • Smart Links: Add ITM parameters to planted Smart Links #3211: The changes in the main PR are related to the modifications in the retrieved PR as both involve updates to the handling of ITM parameters in the context of smart links, specifically through the get_link_href method and the introduction of new parameters in the URL.

Suggested labels

Feature: Traffic Boost, Changelog: Added

Suggested reviewers

  • acicovic

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff369d7 and b0f558c.

📒 Files selected for processing (1)
  • src/Models/class-smart-link.php (9 hunks)
🧰 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 ...

**/*.{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/Models/class-smart-link.php
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: E2E against WordPress latest
🔇 Additional comments (9)
src/Models/class-smart-link.php (9)

42-50: LGTM! The new context property is well-documented.

The property declaration with proper PHPDoc follows WordPress coding standards and clearly documents the purpose of the context property. The initialization to null is appropriate.


268-271: LGTM! Context loading is implemented correctly.

The implementation correctly checks for the existence of the context in post meta before assigning it to the property.


372-374: LGTM! Context saving is implemented appropriately.

The implementation only adds the context to the post meta if it's not null, which is efficient.


477-489: LGTM! Updated ITM parameters with proper context implementation.

The refactored parameter structure now correctly implements the functionality context as described in the PR objectives. The replacement of underscores with hyphens maintains consistency with ITM parameter conventions.


492-501: LGTM! Well-implemented getter method.

The get_context() method is properly documented and follows standard accessor patterns.


742-751: LGTM! Well-implemented setter method.

The set_context() method is properly documented and follows standard mutator patterns.


785-785: LGTM! Array serialization updated to include context.

The context is now properly included in the serialized array representation of the smart link.


979-980: LGTM! Documentation vartype fixed.

The PHPDoc has been updated to correctly include the Inbound_Smart_Link type in the @var annotation.


1037-1040: LGTM! Code formatting improved.

The parameter alignment in the method call has been improved for better readability.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_context method 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

📥 Commits

Reviewing files that changed from the base of the PR and between 199141e and bef03af.

⛔ Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is 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.php
  • tests/Integration/RestAPI/ContentHelper/EndpointSmartLinkingTest.php
  • src/rest-api/content-helper/class-endpoint-smart-linking.php
  • src/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 addSmartLinkITMParamsToURL function properly implement the updated parameter values:

  • Updated campaign from 'parsely-pch' to 'wp-parsely' for better brand alignment
  • Added new medium parameter with value 'smart-link' for clearer categorization
  • Changed source from 'smart-link' to 'smart-linking' to differentiate from Traffic Boost

These 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 $context is 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 $context property 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_context method 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.

vaurdan and others added 4 commits March 27, 2025 10:54
…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>
@vaurdan vaurdan requested a review from acicovic March 27, 2025 11:11
Copy link
Collaborator

@acicovic acicovic left a comment

Choose a reason for hiding this comment

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

It seems that some unnecessary trailing spacing was introduced in 50e92f5.

@vaurdan vaurdan requested a review from acicovic April 2, 2025 11:43
@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 2, 2025

@acicovic should be fixed now, not sure why that was introduced in the first place though.

@acicovic acicovic merged commit 1338df1 into add/traffic-boost Apr 4, 2025
38 checks passed
@acicovic acicovic deleted the update/smart-links-itm-params-context branch April 4, 2025 08:36
github-actions bot added a commit that referenced this pull request Apr 9, 2025
…arams-context Smart Links: Add functionality context to ITM parameters" (1338df1)
@acicovic acicovic modified the milestones: 3.18.0, 3.19.0 Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: Engagement Boost Ticket/PR related to Engagement Boost Feature: PCI Ticket/PR related to Content Intelligence

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants