Pageviews are incremented with the new value instead of overwriting them leading to a different view count than what is in GA4 if the processed nodes are limited

Created on 20 June 2023, over 1 year ago

Problem/Motivation

src/GoogleAnalyticsCounterAppManager.php does this merge query for writing the results from GA4 to each URLs:

        $this->connection->merge('google_analytics_counter')
          ->key('pagepath_hash', md5($page_path))
          ->fields([
            'pagepath' => $page_path,
            'pageviews' => $value,
          ])
          ->expression('pageviews', 'pageviews + :pageviews', [':pageviews' => $value])
          ->execute();

That means if for /node/1 the viewcount was saved as 325, then GA4 reports new 410 view count, then 325+410=735 will be saved instead of 410.

Steps to reproduce

You need to set "Update pageviews for content created in the last X days" or "Update pageviews for the last X content".
Run cron multiple times.

Proposed resolution

Remove that expression from the merge query.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024