Many web analytics software packages enable you to measure traffic by adding unique HTTP query string parameters to URLs. By modifying a base URL (such as https://www.example.com/path/to/page
) and adding query string parameters, you can measure user behavior and engagement. For example, the following URL contains two common query string parameters (utm_medium
and utm_source
) appended to the base URL:
https://www.example.com/path/to/page?utm_medium=notification&utm_source=email
On Cloud Platform, Varnish® strips the query strings from popular web analytics software packages and then stores a cached version of the page according to the base URL, instead of the full URL with appended query strings, without breaking the reporting to your web analytics software. Cloud Platform will serve the version of the page stored in Varnish cache for subsequent requests that match the base URL, varying only by the query string parameters, which enables measurable marketing campaigns while preserving website performance.
For example, Cloud Platform will display each of the following webpages as the same cached webpage (https://www.example.com/path/to/page
) to a visitor:
https://www.example.com/path/to/page?utm_medium=notification
https://www.example.com/path/to/page?_ga=1.000001
https://www.example.com/path/to/page?utm_medium=notification&utm_source=email
https://www.example.com/path/to/page?utm_medium=notification&utm_source=facebook
When serving a webpage to a visitor, Varnish performs the following steps:
- Strip the query string parameters from the requested URL.
- Add an
X-Acquia-Stripped-Query
header that contains the query string parameters to the HTTP request. - Redirect the request to both the non-bare and
https://
prefixed version of the domain. - If permitted by caching policy, cache the returned webpage according to the base URL.
- Serve the content to the visitor.
Varying cache by stripped queries
To vary cache by stripped queries, use the HTTP Cache Control module. This module allows you to add X-Acquia-Stripped-Query
to the Vary header and hence, varies the caching of their responses by the stripped queries as if the queries were never stripped in the first place. If you follow this mechanism, you don’t need to create a custom Drupal module.
Alternatively, if the X-Acquia-Stripped-Query
header is present on webpages that shouldn’t be cached, you can create a custom Drupal module to add the following header to the responses to prevent caching:
Cache-Control: must-revalidate, no-cache, private
For tools to inspect the HTTP response headers of a webpage, see browser developer tools. For methods of controlling caching for certain types of responses, see Set max-age headers for specific pages, files, or paths.
Using the X-Acquia-Stripped-Query response header in Drupal
The following Drupal functions allow for uncacheable requests by utilizing the content of X-Acquia-Stripped-Query
, which can be accessed by parsing the variable $_ENV['HTTP_X_ACQUIA_STRIPPED_QUERY']
:
Drupal version | Function |
---|---|
Drupal 7 | drupal_parse_URL |
Current Drupal version | UrlHelper::parse |
Redirecting while keeping query parameters
There are use cases when you need to have redirects that include the web analytics query parameters.
With the removal of these, via Varnish®, there are a number of strategies that can be used to handle such redirect use cases.
Read the Support article, Handling redirects while keeping web analytics/UTM query parameters, to learn how to implement these strategies.