Insert Google Analytics


The 'Insert Google Analytics' filter is enabled by specifying:

ModPagespeedEnableFilters insert_ga
ModPagespeedAnalyticsID <Analytics ID>
pagespeed EnableFilters insert_ga;
pagespeed AnalyticsID <Analytics ID>;

in the configuration file. As of the default snippet is now analytics.js. To insert ga.js instead, set:

ModPagespeedUseAnalyticsJs false
pagespeed UseAnalyticsJs false;


The 'Insert Google Analytics' filter adds the basic Google Analytics javascript snippet to each HTML page. If the page already has a Google Analytics snippet inside <head> with the specified ID, then no additional snippet will be added. If another Google Analytics snippet is on the page with a different ID, then an additional snippet will be added with the ID specified in with AnalyticsID. In order to avoid any strange Google Analytics reporting, make sure that the ID specified in the configuration file matches the one used on your site.

This filter does not require the make_google_analytics_async filter. The Google Analytics snippets inserted by insert_ga are already asynchronous.

See this example of this filter in action.