Delete Google Adwords gclid query string in Nginx

By using Google AdWords, you can get traffic to your WordPress site and increase loyal viewers and customers. You can find visitors who click on your Google ads and have a slower experience. Google adds a query string that looks something like this ?gclid=fgassd45hj78s1 and which bypasses any caching supported on your server. Google uses this query string for tracking, however Google tracks using client side JavaScript, which means we can remove this Google AdWords query string providing faster page loading for customers and still tracked with Google Analytics.

This tutorial is for removing the GCLID query string in Nginx.

Speed ​​tests with and without Google Adwords query string

Using Pingdom, on the first page of this site, loading into 339 ms no query string

When repeating speed test after adding query string ?gclid=fgassd45hj78s1, load increased to 1.08 seconds because the page bypassed the cache.

Read on to learn how to remove this Nginx query string for WordPress.

How to remove Google Adwords gclid query string in Nginx

In your nginx virtual host file, usually in the file /etc/nginx/sites-available or /etc/nginx/vhosts , add this snippet

                        #удаление строки запроса gclid
if ($args ~* "gclid") {
    #? в uri? вырезать строку запроса gclid
    rewrite ^(.*)$ $uri? permanent;

Save the virtual host and then check the Nginx configuration syntax to OK.

                        sudo nginx -t

Restart the Nginx service if there were no syntax errors.

                        sudo service nginx reload

Now when you test the URL, then the query string ?gclid you will see no more.

Related Posts