Support Google Analytics 4 / gtag.js

Created on 22 June 2022, over 2 years ago
Updated 25 June 2023, over 1 year ago

Problem/Motivation

Google is requiring websites to upgrade to Google Analytics 4 (gtag.js), and UA will stop receiving data in July 2023. There is a RTBC patch for the main GA module ✨ Support Google Analytics 4/gtag.js Fixed , but it is not able to track eCommerce conversions in Ubercart, since the uc_googleanalytics module uses the now deprecated analytics.js (or ga.js).

Steps to reproduce

Install Ubercart up to 7.13 or 7.x-3.x.dev (17 May 2022) and they use analytics.js or ga.js, but not gtag.js.

Proposed resolution

uc_googleanalytics module needs to be upgraded to support gtag.js.

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada arvana Canada

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 States mglaman WI, USA

    Also, from reading this article https://developers.google.com/analytics/devguides/migration/ecommerce/gt... the UA ecommerce events will be translated, so they can be fixed out of band of the GA module.

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

    Fellas apologies for the delay. I have an update to uc_googleanaltycs code, that we had to do in rush. Attached is the patch. Sorry I did not post the patch here before. Also, excuse all watchdogs in there. We are still using them to debug. The solution works and it is tracking our sales. If you chose to try it, I recommend to leave/modify watchdog messages to you can evaluate them for your own eCommerce.
    We did have to create a manufacturer field for our product so the brand can be tracked as well. Also thank you for contributing at the GA4 ( https://www.drupal.org/project/google_analytics/issues/3174214 ✨ Support Google Analytics 4/gtag.js Fixed ) I have used that and google resources to get this one done.

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

    Thanks @ deja711

    Just patched and will wait for data. I'll report back when I get some data or feedback.

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

    So far I'm getting results, however I still have the problem of UC only sending 1 out of every 4 orders to analytics.

    It's better than nothing, but pretty much worthless info at the end of the day.

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

    philsward, you are welcome. I am glad you got to try it. Regarding accurate reporting, I might have good news for you. We are using Authorize.net and paypal. Both GA3 and GA4 match when it comes to completed transactions. I did notice the following (which might affect you):
    a) GA4 has 24h or so delay, not as instant as GA3. So to get accurate data I usually compare from 48 hours just to be sure.
    b) For paypal, sometimes customers do not return to the checkout complete page and that does not trigger analytics. I tried to compensate for that with paypal automatic setting to return user to site, and that helped but did not eliminate it completely.

    Also at the moment, we are using the google analytics version patched before shim was added. I am still to try and understand one with shim, which is current.

    At the moment we are happy with data on GA4. It is correlating (we are running GA3/UA properly also in parallel). That is all fine. My biggest problem is that we do not have support for (view item details, Add/remove a product from a shopping cart, Initiate the checkout process). It looks like this was never implemented for uc_googleanalytics even in GA3/UA version. See here:
    https://developers.google.com/analytics/devguides/collection/ga4/ecommer...

    I am going to tackle that now, although I am not sure yet where I should place that code.

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

    @deja711 anything you can do will be awesome. This area hasn't seen any love in ages.

    I did check again and the reporting is still the same, about 1 in 4.

    It's possible it's related to the payment module(s) which is Stripe Checkout (custom coded module) and the stock UC Paypal module.

    If you have any interest in Stripe, I can share what I have. It uses their checkout API which puts ALL of the CC data onto their pages/servers so my sites touch zero of that info. I used to use Authorize but they just weren't staying up with the times. We started getting a lot of fraudulent activity and authorize wasn't picking up on it. Stripe seems to be a lot better about that. I have my gripes but overall, it was a good move.

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

    Hello. I'm confused. Is your patch required with the new (shimmed) GA4 version of Analytics Module? mglaman's #4 comment is what is confusing me.

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

    @philsward:
    Regarding your 1 in 4 issues. Please check that order complete page is being generated/captured, that was my issue with paypal. You should not settle for 1 in 4 detections, as it might be something simple. Thank you for sharing about Stripe, I will have to check it out. For your authorize.net sites, don't forget to login there and increase your security/antifraud measures (you probably know that, but just in case).
    Regarding GA4, I will keep you in the loop as we make progress. We are adding add-to-cart, remove-cart, initiate-checkout, and product-details-view to GA4 events. If you look right now you will see that GA4 is not getting that data. That is because the previous UA/GA3 did not send that data either. We just figured out we can put it all in uc_googleanalytics and use hooks for each of those events.

    @ohanm:
    Good observation. The latest shimmed GA4 version (latest patch) gave me problems. I am not sure if is fully ready, not sure if it worked for you or gave you issues. I will have to return to it and check it out more and see how it works. Following are some questions or areas I need to understand:
    A) It is not clear to me where shims would come to play besides in uc_googleanalytics
    B) uc_googleanalytics is missing a bunch of events I need to use for GA4. So I will have to add them to uc_googleanalytics.
    C) We would like to run both GA4 and UA/GA3 in parallel right now until the end, and the way it is working for us is that we are simply sending the data via new GA4 framework. End result is that I can use both google analytics to analyze my data. I would like to know how others are doing here or what they think.

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

    @deja711
    > Regarding your 1 in 4 issues. Please check that order complete page is being generated/captured, that was my issue with paypal.
    > You should not settle for 1 in 4 detections, as it might be something simple.

    As far as I know it is? I'm not a programmer so digging into that is difficult for me. Agreed that 1 in 4 isn't good :(

    > Thank you for sharing about Stripe, I will have to check it out.

    I'll try to remember to add it to my github so you can download it. I'll let you know.

    > Regarding GA4, I will keep you in the loop as we make progress. We are adding add-to-cart, remove-cart, initiate-checkout, and product-details-view to GA4 events. If you look right now you will see that GA4 is not getting that data. That is because the previous UA/GA3 did not send that data either. We just figured out we can put it all in uc_googleanalytics and use hooks for each of those events.

    Super excited!

    > The latest shimmed GA4 version (latest patch) gave me problems. I am not sure if is fully ready, not sure if it worked for you or gave you issues.

    This may be part of my problem... I'm using the latest with the shim and it might be possible that the shim is causing problems.

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

    deja711, which patched version of GA are you using with your uc_googleanalytics_patch.txt? It is #53 ? ie. https://www.drupal.org/files/issues/2022-04-27/google_analytics-support-... β†’

  • @deja711: thanks for your patch, it works great even if not all the payment modules redirect you to the default Thankyou page (checkout\complete). I'm using GestPay module and I had to customize something...

    Now I'm looking for an implementation for the "add-to-cart" event, there's something to share right now?

    Thanks in advance

  • Just yesterday, I found another fault on the patch. If I'm paying with Paypal (or other payment system that use an external gateway) and, after the payment, the user close the browser BEFORE redirection to the Thank you page, obviously no conversion is tracked

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

    I'm using the patch with Google Analytics 7.x-2.8, stock UC authorize.net for credit cards and stock UC PayPal Website Payments Standard and I am getting 100% of orders coming through. Thanks deja711 for the patch

Production build 0.71.5 2024