Support Google Analytics 4

Created on 17 February 2021, almost 4 years ago
Updated 23 May 2023, over 1 year ago

Problem/Motivation

Google Analytics 4 is here, so we must to give support. https://blog.google/products/marketingplatform/analytics/new_google_anal...

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom gMaximus

    I'm trying to get this working with D9, commerce_google_analytics (8.x-1.0-beta1) and google_analytics (4.0.0). I use the D7 version of these modules and it was just a case of turning them on and the order info went across. This was using the universal analytics, not GA4.

    I tried that here and no commerce info is going across. Is there more configuration that needs doing on the website or in Google Analytics? Does this depend on any other patches or module versions?

    I ask about patches because if I create a rule and add the push event action, I get:

    "Notice: Undefined index: context in ga_push_form_rules_expression_edit_alter() (line 1123 of /ga_push/ga_push.module)
    "Notice: Undefined index: event in ga_push_form_rules_expression_edit_alter() (line 1123 of /ga_push/ga_push.module)"
    "Error: Unsupported operand types in ga_push_form_rules_expression_edit_alter() (line 1123 of ga_push/ga_push.module)"

    I figured I may have to create my own rules, where they were default in D7? Happy to contribute a screencast of setting it up. The readme is about D7.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom steven jones

    I have need for GA4 integration for a client of ours, and I wonder if it would make sense to integrate this Drupal module with a wrapping library like:

    https://github.com/br33f/php-GA4-Measurement-Protocol

    So that that library can do the heavy lifting of formatting all the data etc and we can build up the higher level objects from the data passed in and then send.

    In terms of implementation, maybe it would also make sense to consider this as an alternative method so that the site admin can switch over, and, if we wanted to be super nice, could potentially provide another method that calls both GA4 and UA measurement protocol methods so that for the next few months data is logged in both APIs.

    Someone on this thread do shout if you've got better ideas, or a reason why the above is silly, otherwise I'll get cracking on that.
    The current working the Merge Request kinda looks like a single person scratching their use-case-itch, rather than trying to do general support for server side GA4, which quite a few people are going to need I think.

  • πŸ‡ΊπŸ‡ΈUnited States scottsawyer Atlanta

    I just wanted to pipe in, if you are using Commerce Google Analytics, you need the patch from the MR here: https://www.drupal.org/project/commerce_google_analytics/issues/3285744 β†’

    We're running this in D9, but only for commerce data. The only configuration is to select Commerce Enhanced, make sure you enter the GA4 credentials. I just did the bare minimum to get GA4 working with Commerce Google Analytics, I am sure there is a lot of improvements that could be made.

  • πŸ‡¬πŸ‡§United Kingdom gMaximus

    @scottsawyer Thanks for replying. I really appreciate it.

    I've applied the patch from the other issue and here. Using the dev branch for both. I'm receiving this error when completing checkout:

    AH01071: Got error 'PHP message: Error: Class 'Drupal\\ga_push\\GA4Service' not found in /web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 #0 /web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService()\n#1 /web/core/lib/Drupal.php(197): Drupal\\Component\\DependencyInjection\\Container->get()\n#2 /web/modules/contrib/ga_push/inc/ga_push.utmp.php.inc(48): Drupal::service()\n#3 /web/modules/contrib/ga_push/ga_push.module(214): ga_push_method_utmp_php()\n#4 /web/modules/contrib/ga_push/ga_push.module(471): ga_push_add()\n#5 /...', referer: /checkout/108/review

    I did clear the cache after updating to dev and applying the patches.

    A couple of other questions:

    1. What default method should I select on the ga_push settings form?
    2. Where are the "Commerce Enhanced" settings you mention? Drupal or Google? I can't seem to find it in either.
  • πŸ‡¬πŸ‡§United Kingdom gMaximus

    I've tried all the default methods except GA.js as it says deprecated. None throw errors except for Measurement Protocol (php). That throws the error above?

    With the others, checkout is completed but nothing has appeared in Analytics. I made a couple of orders yesterday.

  • πŸ‡¬πŸ‡§United Kingdom gMaximus

    It's working for me now (Measurement Protocol (php)).

    I needed to temporally add $settings['class_loader_auto_detect'] = FALSE; to my settings.php to have the class load. So a APC caching problem my end. Many thanks.

  • πŸ‡ΊπŸ‡ΈUnited States rpataca

    Any plans to back port to D7?

  • πŸ‡ΊπŸ‡ΈUnited States JordanMagnuson

    I'm also interested in a D7 backport...

  • πŸ‡¦πŸ‡ΊAustralia imclean Tasmania

    @rpataca, @JordanMagnuson then port it. You can submit a patch or MR and see if it gets accepted.

  • πŸ‡¬πŸ‡§United Kingdom MrDaleSmith

    The required br33f/php-ga4-mp library is listed in the composer.json file, and

    new BaseRequest($options['cid']);

    in ga_push/inc/ga_push.php_mp.inc requires anyone using the function to set their Google Analytics client id in the options even if using the default id that the code itself has loaded from configuration a few lines before. I've attempted to fix these in the fork, but for some reason I can't get access to it, so I'll have to leave it for someone else to resolve.

  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    @darthsteven Please give us a guideline for the description.

    I tested the MR and seems to work right so, is ready to merge after those changes.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί
Production build 0.71.5 2024