Plugins are scripts that enhance the functionality of analytics.js to aid in measuring user interaction. Plugins are typically specific to a set of features that may not be required by all Google Analytics users, such as ecommerce or cross-domain tracking, and are therefore not included in analytics.js by default.
This guide explains how to require and use analytics.js plugins.
The require command takes the name of a plugin and registers it for use with the ga()
command queue. If the plugin accepts configuration options, those options can be passed as the final argument to the require command.
The following is the full require command's signature:
ga('[trackerName.]require', pluginName, [pluginOptions]);
For example, here is how you would require the Enhanced Ecommerce plugin for use with the default tracker:
ga('require', 'ec');
And here is how you would require the Display Features plugin for a tracker named "myTracker" and pass a configuration option that overrides the default cookie name value:
ga('myTracker.require', 'displayfeatures', {
cookieName: 'display_features_cookie'
});