Zum Inhalt

Mirrored documentation

This page is a faithful mirror of the original Apache mod_pagespeed documentation (Apache License 2.0). The upstream project was retired and the modpagespeed.com domain is now operated by an unrelated commercial vendor; we host the original reference so users of nginx-module-pagespeed from GetPageSpeed can rely on a stable copy.

Insert Google Analytics

Configuration

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

Apache:

ModPagespeedEnableFilters insert_ga
ModPagespeedAnalyticsID <Analytics ID>

Nginx:

pagespeed EnableFilters insert_ga;
pagespeed AnalyticsID <Analytics ID>;

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

Apache:

ModPagespeedUseAnalyticsJs false

Nginx:

pagespeed UseAnalyticsJs false;

Description

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.