Skip to content

Keep the visit's campaign name case on conversions so Campaign Names doesn't split one campaign into two rows - #25831

Closed
AltamashShaikh wants to merge 1 commit into
6.x-devfrom
DEV-21156
Closed

AltamashShaikh wants to merge 1 commit into
6.x-devfrom
DEV-21156

Conversation

@AltamashShaikh

Copy link
Copy Markdown
Contributor

Description

When MarketingCampaignsReporting is active (with its default "do not change case of UTM parameters" setting), a campaign with capitals such as QA-Spring shows up twice in core's Campaign Names report (Referrers.getCampaigns): one QA-Spring row with the visits and no conversions, and a qa-spring row with 0 visits that holds all goal conversions and revenue.

Root cause: the plugin writes log_visit.referer_name / referer_keyword in their original case. For conversions, Referrers\Columns\Base::getValueForRecordGoal() always lowercases campaign name and keyword (setCampaignValuesToLowercase()). So log_conversion stores qa-spring. The Referrers archiver groups visits and conversions by the exact referer_name, which gives two rows.

Fix: after lowercasing, if the conversion is credited to a campaign and the visit is a campaign whose stored name (or keyword) is the same value ignoring case, the conversion uses the visit's stored spelling. This is done in a small private helper. Masked placeholder values and empty values keep their current path. Without the plugin, or with the plugin's lowercase setting, the visit values are already lowercase, so nothing changes. A different campaign from the _rcn attribution cookie is still lowercased as before. Goals and ecommerce orders both go through this path.

Known limit: if the plugin keeps case and the attribution cookie names an older campaign than the visit, that conversion is still lowercased. Fixing that would need core to share the plugin's casing setting (a new event contract), which is out of scope here.

Tests: added ReferrerAttributionTest::testConversionKeepsCaseOfCampaignStoredOnVisit. It tracks a campaign visit, sets the visit's campaign name/keyword to original case (as the plugin writes them), then tracks a goal conversion and an ecommerce order. It asserts both conversions store QA-Spring / Spring-KW and that Referrers.getCampaigns returns one QA-Spring row with 1 visit and 2 conversions. The test failed before the fix (conversions stored qa-spring / spring-kw) and passes after it. The other testConversion* tests in the file still pass. PHPCS and PHPStan are clean on the changed files. The existing lowercase attribution cases in the same file's data provider cover the unchanged behaviour without the plugin; I didn't run the full data provider locally because it is slow, so CI will run it.

Checklist

  • [✖] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Review

🤖 Generated with Claude Code

Fixes #25719

When a plugin such as MarketingCampaignsReporting stores the campaign name
and keyword on the visit in their original case, conversions of that campaign
were still lowercased by core. The Campaign Names report then split one
campaign into a row with the visits and a 0-visit row with the conversions.

Conversions now reuse the visit's stored spelling when it is the same
campaign value ignoring case. Without such a plugin the visit values are
already lowercase, so nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AltamashShaikh AltamashShaikh added this to the 6.1.0 milestone Nov 26, 2026
@AltamashShaikh
AltamashShaikh requested a review from a team November 26, 2026 02:32
@nathangavin nathangavin self-assigned this Nov 26, 2026
$this->setCampaignValuesToLowercase($type, $name, $keyword);

if ($type === Common::REFERRER_TYPE_CAMPAIGN) {
$name = $this->getCampaignValueAsStoredOnVisit($visitor, 'referer_name', $name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR breaks MarketingCampaignsReporting's tests: in that plugin's lowercase mode, conversions now get the visit's original-case campaign name, which the description says won't happen.

@@ -776,6 +776,11 @@ public function getValueForRecordGoal(Request $request, Visitor $visitor)

$this->setCampaignValuesToLowercase($type, $name, $keyword);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A returning visitor who converts on a later visit is still stored in lowercase, so the campaign still splits into two rows, even though the plugin already listens to an event core could send to avoid this.

]]);
}

public function testConversionKeepsCaseOfCampaignStoredOnVisit(): void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new test only covers a conversion whose campaign matches the visit, so it misses a different-campaign cookie, a conversion with no cookie, a keyword-only mismatch and a non-campaign visit.

@AltamashShaikh

Copy link
Copy Markdown
Contributor Author

Auto-fix agent: these checks still fail after 3 attempts: All required tests passed, PHP (IntegrationTestsPlugins, bucket 4/10, 8.6, MYSQLI, Mysql, 8.0), PHP (SystemTestsPlugins, bucket 9/10, 8.1, PDO_MYSQL, Mysql, 8.0), PHP (SystemTestsPlugins, bucket 9/10, 8.2, PDO_MYSQL, Mariadb, 10.6), PHP (SystemTestsPlugins, bucket 9/10, 8.6, MYSQLI, Mysql, 8.0), UI-. A developer needs to look at them; the agent will not push to this PR again.

@AltamashShaikh

Copy link
Copy Markdown
Contributor Author

@nathangavin SClosing this one, as these are AI fixes and we are working to make it better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants