Link Tracker functionality for WordPress.
- Includes PHP and JS functions that allow adding parameters to URLs.
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).
Run npm run build
to rebuild files and commit the new build files (be sure to remove the old version files).
composer config repositories.newfold composer https://newfold-labs.github.io/satis/
composer require newfold-labs/wp-module-link-tracker
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