Skip to content

Commit c9dd5e2

Browse files
committed
Remove all marketing get parameters to minimize the cache
1 parent 71432ae commit c9dd5e2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
namespace Magento\PageCache\Model\App\Request\Http;
99

1010
use Magento\Framework\App\Http\Context;
11+
use Magento\Framework\App\PageCache\Identifier;
12+
use Magento\Framework\App\PageCache\IdentifierInterface;
1113
use Magento\Framework\App\Request\Http;
1214
use Magento\Framework\Serialize\Serializer\Json;
13-
use Magento\Framework\App\PageCache\IdentifierInterface;
1415

1516
/**
1617
* Page unique identifier
@@ -38,9 +39,11 @@ public function __construct(
3839
*/
3940
public function getValue()
4041
{
42+
$pattern = Identifier::PATTERN_MARKETING_PARAMETERS;
43+
$replace = array_fill(0, count($pattern), '');
4144
$data = [
4245
$this->request->isSecure(),
43-
$this->request->getUriString(),
46+
preg_replace($pattern, $replace, $this->request->getUriString()),
4447
$this->context->getVaryString()
4548
];
4649

lib/internal/Magento/Framework/App/PageCache/Identifier.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
*/
1414
class Identifier implements IdentifierInterface
1515
{
16+
/**
17+
* Pattern detect marketing parameters
18+
*/
19+
public const PATTERN_MARKETING_PARAMETERS = [
20+
'/&?gclid\=[^&]+/',
21+
'/&?cx\=[^&]+/',
22+
'/&?ie\=[^&]+/',
23+
'/&?cof\=[^&]+/',
24+
'/&?siteurl\=[^&]+/',
25+
'/&?zanpid\=[^&]+/',
26+
'/&?origin\=[^&]+/',
27+
'/&?fbclid\=[^&]+/',
28+
'/&?mc_(.*?)\=[^&]+/',
29+
'/&?utm_(.*?)\=[^&]+/',
30+
'/&?_bta_(.*?)\=[^&]+/',
31+
];
32+
1633
/**
1734
* @var \Magento\Framework\App\Request\Http
1835
*/
@@ -50,9 +67,11 @@ public function __construct(
5067
*/
5168
public function getValue()
5269
{
70+
$pattern = self::PATTERN_MARKETING_PARAMETERS;
71+
$replace = array_fill(0, count(self::PATTERN_MARKETING_PARAMETERS), '');
5372
$data = [
5473
$this->request->isSecure(),
55-
$this->request->getUriString(),
74+
preg_replace($pattern, $replace, $this->request->getUriString()),
5675
$this->request->get(\Magento\Framework\App\Response\Http::COOKIE_VARY_STRING)
5776
?: $this->context->getVaryString()
5877
];

0 commit comments

Comments
 (0)