PHPackages                             pixelistik/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. pixelistik/url-campaignify

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

pixelistik/url-campaignify
==========================

A PHP class to help add web analytics campaigns to URLs.

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

Since Feb 25Pushed 13y ago2 watchersCompare

[ Source](https://github.com/pixelistik/url-campaignify)[ Packagist](https://packagist.org/packages/pixelistik/url-campaignify)[ RSS](/packages/pixelistik-url-campaignify/feed)WikiDiscussions master Synced today

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

[![Build Status](https://camo.githubusercontent.com/d0abfdc63b982635ff93141f99153b5386ad7a8c746b419c7edbfd22dbc11614/68747470733a2f2f7472617669732d63692e6f72672f706978656c697374696b2f75726c2d63616d706169676e6966792e706e67)](https://travis-ci.org/pixelistik/url-campaignify)

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

[](#url-campaignify)

### Background

[](#background)

The open source web analytics tool Piwik can use campaigns and keywords for categorising incoming links. They work by appending additional GET params to your HTTP URLs:

```
http://my-site.tld/?pk_campaign=newsletter-5&pk_kwd=header-link

```

[Read more about this technique in the Piwik docs](http://piwik.org/docs/tracking-campaigns/)

[Google analytics](https://support.google.com/analytics/bin/answer.py?hl=en&answer=1033863)and probably most other analytics tool do basically the same thing.

### 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&pk_campaign=newsletter-5&pk_kwd=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?pk_campaign=news&pk_kwd=link-1
here is a long and verbose text and another link at the end:
http://my-site.tld?pk_campaign=news&pk_kwd=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 not automatically included, so the above instance will *not* touch URLs on `www.my-site.tld`. You can specify multiple domains as an array, though:

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

```

### 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  pixelistik/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

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% 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

4877d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e896d31916d54e11b4ca7f95cf1dcda92920e24530ff121a2c143af3c2bd7797?d=identicon)[pixelistik](/maintainers/pixelistik)

---

Top Contributors

[![pixelistik](https://avatars.githubusercontent.com/u/170929?v=4)](https://github.com/pixelistik "pixelistik (41 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/pixelistik-url-campaignify/health.svg)

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

PHPackages © 2026

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