PHP code example of ministryofweb / analytics-campaign-urls

1. Go to this page and download the library: Download ministryofweb/analytics-campaign-urls library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ministryofweb / analytics-campaign-urls example snippets




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