Skip to content

newfold-labs/wp-module-link-tracker

Newfold Logo

WordPress Link Tracker Module

Link Tracker functionality for WordPress.

Module Responsibilities

  • Includes PHP and JS functions that allow adding parameters to URLs.

Releases

1. Bump Version

Update the module versions in the bootstrap.php file (the NFD_LINK_TRACKER_MODULE_VERSION const) and in the package.json file (the package version).

2. Build

Run npm run build to rebuild files and commit the new build files (be sure to remove the old version files).

Installation

1. Add the Newfold Satis to your composer.json.

composer config repositories.newfold composer https://newfold-labs.github.io/satis/

2. Require the newfold-labs/wp-module-link-tracker package.

composer require newfold-labs/wp-module-link-tracker

3. How to use the module

The module offers the ability to use a PHP and a JS function to add parameters to the URL.

For PHP applications, you can use the build_link function in this way:

use function NewfoldLabs\WP\Module\LinkTracker\Functions\build_link as buildLink;

$url = 'https://example.com';
$parameters = array(
    'utm_source' => 'newsletter',
    'utm_medium' => 'email',
    'utm_campaign' => 'spring_sale',
);
$trackedUrl = buildLink($url, $parameters);
echo $trackedUrl; // Outputs: https://example.com/?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale   

If you don't provide any parameters, the function will return the original URL adding default parameters.

use function NewfoldLabs\WP\Module\LinkTracker\Functions\build_link as buildLink;

$url = 'https://example.com';

$trackedUrl = buildLink($url);
echo $trackedUrl; // Outputs: https://example.com/?channelid=P99C100S1N0B3003A151D115E0000V112&utm_source=%2Fwp-admin%2Fadmin.php%3Fpage%3Dbluehost%23%2Fhome&utm_medium=bluehost_plugin   

You can also use the hook "nfd_build_url" to your urls. In this way the module will hook and change the URL automatically.

$tracked_url = apply_filters( 'nfd_build_url', 'https://example.com' ); 
echo $tracked_url // Outputs: https://example.com/?channelid=P99C100S1N0B3003A151D115E0000V112&utm_source=%2Fwp-admin%2Fadmin.php%3Fpage%3Dbluehost%23%2Fhome&utm_medium=bluehost_plugin

For JavaScript applications, you can use the NewfoldRuntime.linkTracker window object.

The object exposes the addUtmParams function. You can use it like this:

const url = 'https://example.com';

let trackerUrl = window.NewfoldRuntime.linkTracker.addUtmParams(url, {
        utm_source: 'newsletter',
        utm_medium: 'email',
        utm_campaign: 'spring_sale',
    });

console.log(trackedUrl); // Outputs: https://example.com/?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale

If you don't provide any parameters, the function will return the original URL adding default parameters.

const url = 'https://example.com';


let trackerUrl = window.NewfoldRuntime.linkTracker.addUtmParams(url);
console.log(trackedUrl); // Outputs: https://example.com/?channelid=P99C100S1N0B3003A151D115E0000V112&utm_source=%2Fwp-admin%2Fadmin.php%3Fpage%3Dbluehost%23%2Fhome&utm_medium=bluehost_plugin

More on Newfold WordPress Modules

About

A WordPress module that adds tracking params

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •