vovafeldman
vovafeldman

Reputation: 595

How to disable Google Analytics pageviews tracking but keep event tracking?

I have a WordPress plugin which bloggers can opt-in for tracking. The data is used to improve the UX in yhe plugin's management dashboard settings pages.

Since we are only interested to track some button click events and don't really need the "pageviews" tracking, is there any way to tell Google to disable the pageviews tracking? I want to respect the publishers privacy as much as I can, and if there's no reason to track pageviews I would prefer to block it.

Upvotes: 1

Views: 3931

Answers (2)

ivan
ivan

Reputation: 21

Disable pageview tracking The default behavior of this snippet is to send a pageview hit to Google Analytics. This is the desired behavior in most cases; pageviews are automatically tracked once you add the snippet to each page on your site. However, if you don’t want the snippet to send a pageview hit to Google Analytics, set the send_page_view parameter to false:

gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });

From :https://developers.google.com/analytics/devguides/collection/gtagjs/#disable_page_view_tracking

Upvotes: 2

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116918

You could do this with the Measurement Protocol directly. The Measurement protocol is just some HTTP posts or gets that send the data directly to your Google Analytics account. The JavaScript code that you get from Google basically does just that.

It is a little tricky there are some required fields you have to send or the data wont record correctly. But if all you want to be able to do is track some button clicks sending the events along shouldn't be to hard.

This is untested example:

http://www.google-analytics.com/collect?v=1&tid=UA-XXX-Y&cid=35009a79-1a05-49d7-b876-2b884d0f825b&t=event&ec=file&ea=upload&userclicked&ev=1

CID just needs to be a session id some way of knowing one user session from another.

NOTE: This will not record all of the normal data. you are going to loose things like language, location, pagepath. This is probably only going to store the event nothing else. I would consider putting it in its own web property to keep the data separate from any true Google Analytics recorded data.

Upvotes: 0

Related Questions