Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'keyEvents:viewed_pricing_page' for key 'PRIMARY': INSERT INTO "google_analytics_reports_fields"

Created on 25 October 2024, 21 days ago

Problem/Motivation

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'keyEvents:viewed_pricing_page' for key 'PRIMARY': INSERT INTO "google_analytics_reports_fields" ("type", "ui_name", "description", "gaid", "data_type", "column_group", "calculation") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => METRIC [:db_insert_placeholder_1] => Key event count for viewed_pricing_page [:db_insert_placeholder_2] => The count of a specific key event. [:db_insert_placeholder_3] => keyEvents:viewed_pricing_page [:db_insert_placeholder_4] => string [:db_insert_placeholder_5] => Event [:db_insert_placeholder_6] => ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 45 of /var/www/dxpr.com/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).

The module assumes "gaid" is a unique ID in the endpoint where it gets its fields from. It seems like, either the gaid is not unique in the source, or the Field import is wonky.

Steps to reproduce

1. Not sure, have a custom key event / conversion event in your GA4 setup? The event in the error is not in fact duplicated anywhere in the GA4 UI.
2. Go to /admin/config/services/google-analytics-reports-api
3. Press "Import fields" button

When I empty the google_analytics_reports_fields table and try again, same error.

Proposed resolution

I found a patch in an unrelated issue that fixed the problem for me, and for the person whom the patch originates from:

https://www.drupal.org/project/google_analytics_reports/issues/3323218#c... 🐛 Composer Build issue with Google Vendor Libraries Closed: won't fix

https://www.drupal.org/project/google_analytics_reports/issues/3323218#c... 🐛 Composer Build issue with Google Vendor Libraries Closed: won't fix

I'm sharing the patch again here but full credit should go to @scampbell1

Remaining tasks

  • ✅ File an issue
  • ➖ Addition/Change/Update/Fix
  • ➖ Testing to ensure no regression
  • ➖ Automated unit testing coverage
  • ➖ Automated functional testing coverage
  • ➖ UX/UI designer responsibilities
  • ➖ Readability
  • ➖ Accessibility
  • ➖ Performance
  • ➖ Security
  • ➖ Documentation
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • N/A
🐛 Bug report
Status

RTBC

Version

4.0

Component

API module

Created by

🇳🇱Netherlands jurriaanroelofs

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

Comments & Activities

Production build 0.71.5 2024