I want to get the page views that with only the existing pages (i.e. only http status 200, not 404 pages when reporting to GA) of the website on google analytics core reporting api.
I am using laravel-analytics
package to get the analytics data from the api:
use Spatie\Analytics\AnalyticsFacade;
...
$page_reports_data = AnalyticsFacade::performQuery(
$this->period,
'ga:uniquePageviews', //metrics
[
'dimensions' => 'ga:pagePath',
]
);
...
The existing code will get all the visiting page by users whether or not a 404 page. Thanks.
CodePudding user response:
HTTP status codes are not available as a standard dimension in Google Analytics.
You'd need to add a custom dimension containing the response code to your tracking setup in order to be able to distinguish pages based whether they actually exist—if there is no other distinction (e.g. page title or the like) possible.
Note that for some statuses such as 30X redirects, this won't be possible at all as they have no HTTP content where you could embed the Analytics tracking code.