PHPackages                             neoseeker/url-campaignify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. neoseeker/url-campaignify

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

neoseeker/url-campaignify
=========================

A PHP class to help add Google Analytics campaigns to standalone URLs and URLs inside strings (such as emails)

0.2.0(13y ago)045MITPHPPHP &gt;=5.3.0

Since Feb 25Pushed 2y ago4 watchersCompare

[ Source](https://github.com/Neoseeker/url-campaignify)[ Packagist](https://packagist.org/packages/neoseeker/url-campaignify)[ RSS](/packages/neoseeker-url-campaignify/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

URL-Campaignify
---------------

[](#url-campaignify)

### Background

[](#background)

This is a tool to help add Google Analytics campaign tracking paramters to URLs and entire text blocks.

It was [originally written by pixelistik](https://github.com/pixelistik/url-campaignify) to add campaign links for Piwik, an open source web analytics tool.

This fork has been modified to work only with Google Analytics and supports all of GA's campaign paramters for categorising incoming links. This tool works by appending additional GET params to your HTTP URLs:

```
http://my-site.tld/?utm_campaign=newsletter-5&utm_term=header-link&medium=email&utm_source=response

```

[Read more about this on Google analytics](https://support.google.com/analytics/bin/answer.py?hl=en&answer=1033863).

### What

[](#what)

This class aims to make it easier to dynamically append such parameters to URLs.

#### Single URLs

[](#single-urls)

Instead of worrying about `?` and `&` you can just do this:

```
$uc = new UrlCampaignify();

$url = "http://some-blog.tld/cms.php?post=123&layout=default";

$newUrl = $uc->campaignify($url, "newsletter-5", "header-link");

```

The result has properly appended parameters:

```
http://some-blog.tld/cms.php?post=123&layout=default&utm_campaign=newsletter-5&utm_term=header-link

```

#### Text blocks

[](#text-blocks)

You can also throw entire blobs of text at the function. It will find and campaignify all HTTP URLs in it.

```
$uc = new UrlCampaignify();

$text = "Look at http://my-site.tld especially".
        "here: http://my-site.tld/news.htm";

$newUrl = $uc->campaignify($text, "newsletter-5", "header-link");

```

If you are expecting HTML input, it makes sense to only change the URLs in `href` attributes. Use `campaignifyHref()` for this. It will turn

```
See http://site.tld for more information.

```

into

```
See http://site.tld for more information.

```

Have a look at the test cases to see which situations and edge cases have been covered -- or not.

#### Auto-number URLs in text blocks

[](#auto-number-urls-in-text-blocks)

All campaignified URLs in a text block are counted (starting at 1). You can use the current number of a URL in your keyword in `sprintf()` style. This is useful if you want to differentiate between several identical URLs in one text.

```
$uc = new UrlCampaignify();

$text = "Here comes the header link: http://my-site.tld".
        "here is a long and verbose text".
        "and another link at the end: http://my-site.tld";

$newUrl = $uc->campaignify($text, "news", "link-%d");

```

Will give you

```
Here comes the header link: http://my-site.tld?utm_campaign=news&utm_term=link-1
here is a long and verbose text and another link at the end:
http://my-site.tld?utm_campaign=news&utm_term=link-2";

```

#### Domains

[](#domains)

It only makes sense to add campaigns if you actually analyse them. This implies that you control the site and its analytics tool. You can restrict UrlCampaignify to only work on URLs on a given Domain. Just pass it to the constructor

```
$uc = new UrlCampaignify('my-site.tld')

```

Note that subdomains are automatically included (this differ's from the original behaviour), so the above instance *will* touch URLs on `www.my-site.tld`.

You can disable this automatic behaviour by using

```
$uc->set_campaignify_subdomains(false);

```

You can specify multiple domains as an array:

```
$uc = new UrlCampaignify(array('my-site.tld', 'www.my-site.tld', 'my-other-site.tld'))

```

### Major Differences Between This Fork and Original

[](#major-differences-between-this-fork-and-original)

1. Uses only Google Analytics: utm\_campaign, utm\_source, utm\_medium etc. utm\_medium defaults to "email"
2. Subdomains will be modified by default.
3. The campaignify() and campaignifyHref() methods has been modified to accept Google Analytics parameters
4. Campaignify will apply to URLs that do not have utm\_medium set (the original code only applies campaignify if utm\_campaign is not set)
5. Campaignify will not replace utm values already present in URLs.

### Installation

[](#installation)

#### Using composer

[](#using-composer)

URL-Campaignify matches the PSR-0 file layout and is on packagist. You should be able to simply type

```
composer require  neoseeker/url-campaignify:dev-master
composer install

```

to get the latest code from the master branch included into your project.

#### Just grabbing the file

[](#just-grabbing-the-file)

You can also simply download the single file that provides the class:

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4872d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a0c8b14df994bc0b575087f6f0aee2c83bf133407447be775953c6bf1735d84?d=identicon)[Redemption](/maintainers/Redemption)

---

Top Contributors

[![pixelistik](https://avatars.githubusercontent.com/u/170929?v=4)](https://github.com/pixelistik "pixelistik (41 commits)")[![redemption](https://avatars.githubusercontent.com/u/517273?v=4)](https://github.com/redemption "redemption (3 commits)")[![catherinek](https://avatars.githubusercontent.com/u/321611?v=4)](https://github.com/catherinek "catherinek (1 commits)")[![halfdan](https://avatars.githubusercontent.com/u/176576?v=4)](https://github.com/halfdan "halfdan (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/neoseeker-url-campaignify/health.svg)

```
[![Health](https://phpackages.com/badges/neoseeker-url-campaignify/health.svg)](https://phpackages.com/packages/neoseeker-url-campaignify)
```

###  Alternatives

[phpflo/phpflo

Flow-based programming for PHP

2183.3k5](/packages/phpflo-phpflo)[beatswitch/distil

165.9k](/packages/beatswitch-distil)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
