ministryofweb / analytics-campaign-urls
Adds Campaign parameters to URLs
3.0.0
2023-12-05 15:50 UTC
Requires
- php: ^8.1
Requires (Dev)
- ergebnis/composer-normalize: ^2.39
- phpunit/phpunit: ^10.0
- rector/rector: ^0.18.12
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.0
This package is auto-updated.
Last update: 2024-12-07 10:09:30 UTC
README
This library allows it to easily append campaign parameters (e.g. for Google Analytics, Matomo/Piwik or Plausible) to any given URL.
Requirements
At least PHP 8.1 is required to use this library in the current version.
Version 2.x of this library supports PHP versions 7.0 or higher.
Installation
composer require ministryofweb/analytics-campaign-urls
Usage
<?php use MinistryOfWeb\AnalyticsCampaignUrls\Url; use MinistryOfWeb\AnalyticsCampaignUrls\Parameters\GoogleAnalytics; use MinistryOfWeb\AnalyticsCampaignUrls\Parameters\Matomo; $params = new GoogleAnalytics( 'summer', 'banner', 'website', ); $campaignUrlGA = Url::addAnalyticsCampaignParams('https://example.com/', $params); // → https://example.com/?utm_campaign=summer&utm_medium=banner&utm_source=website $campaignUrlGAWithExistingParam = Url::addAnalyticsCampaignParams('https://example.com/?existingparam=1', $params); // → https://example.com/?existingparam=1&utm_campaign=summer&utm_medium=banner&utm_source=website $matomoParams = new Matomo( 'summer', 'banner', 'website', 'keyword', 'content' ); $campaignUrlMatomo = Url::addAnalyticsCampaignParams('https://example.com/', $matomoParams); // → https://example.com/?pk_campaign=summer&pk_medium=banner&pk_source=website&pk_kwd=keyword&pk_content=content