Skip to content

WordPress Plugin: Dynamic Tracking support

Overview

Dynamic Tracking allows developers to send custom events using the Parse.ly tracker. This is typically used on single-page applications (SPAs) or pages with dynamic content. Dynamic Tracking is an advanced feature that requires developers to add custom code.

Implementation example

The Parse.ly WordPress plugin provides an interface to the Parse.ly tracker to write that code. The key to Dynamic Tracking is inserting JS code in the onload method of the Parse.ly tracker, and then calling the trackPageView function.

To hook into the onload method, the plugin provides the wpParselyOnLoad JavaScript hook, which guarantees the function passed to it will be executed in order when the tracker is loaded in a WordPress environment.

For instance, Dynamic Tracking could be added as follows in a PHP file on your theme code:

$script = '
window.wpParselyHooks.addAction("wpParselyOnLoad", "wpParsely", trackingFunc, 10);
function trackingFunc() {
  jQuery("a.next").bind("click", function() {
    var url = this.href,
    urlref = location.href;
     PARSELY.beacon.trackPageView({
      url: url,
      urlref: urlref,
      js: 1
    });
    return true;
  });
}';
wp_add_inline_script( 'wp-parsely-loader', $script );

Notice that the actual JS tracking code is identical to what you’d do for a non-WordPress site. Because of it, please refer to the general Dynamic Tracking documentation for more details on the implementation.

You may want to disable autotracking on the Parse.ly tracker. In the plugin, this can be achieved by selecting “Yes” on the “Disable Autotracking” option in the plugin’s settings page. If you can’t find the option, make sure you have the Advanced Settings section enabled under screen options. This is an advanced feature that should only be used with Dynamic Tracking. Enabling it otherwise can have severe impact on your metrics.

Last updated: August 16, 2023