3f08e8a24916a75afd749c152097f58344819a3a
max
  Thu Mar 2 07:11:02 2023 -0800
Ignore the previous commit in code review, that was all wrong, I was looking at the wrong analytics page and thought it was working. The GA4 system is entirely different and the code now spread out over five source files. Also: The part of cart.c that outputs the <HEAD> is getting worse and worse. To test the new code, set the analyticsKey to the value in the cgi-bin-max sandbox and go to https://analytics.google.com/analytics/web/#/p356133243/realtime. All staff should have access (if not email me or Lou or Hiram), refs #30725

diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index 47e6f55..a3d4185 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -2626,31 +2626,34 @@
  * variables that you don't want to save in the cart between
  * invocations of the cgi-script. */
 {
 struct cart *cart;
 char *db, *org, *pos;
 char titlePlus[2048];
 pushWarnHandler(cartEarlyWarningHandler);
 cart = cartAndCookie(cookieName, exclude, oldVars);
 getDbAndGenome(cart, &db, &org, oldVars);
 pos = cartGetPosition(cart, db, NULL);
 pos = addCommasToPos(db, stripCommas(pos));
 cartSetLastPosition(cart, pos, oldVars);
 safef(titlePlus, sizeof(titlePlus), "%s %s %s %s", 
                     org ? trackHubSkipHubName(org) : "", db ? db : "",  pos ? pos : "", title);
 popWarnHandler();
+
 setThemeFromCart(cart);
+googleAnalyticsSetGa4Key();
+
 htmStartWithHead(stdout, head, titlePlus);
 cartWarnCatcher(doMiddle, cart, htmlVaWarn);
 cartCheckout(&cart);
 cartFooter();
 }
 
 static void cartEmptyShellMaybeContent(void (*doMiddle)(struct cart *cart), char *cookieName,
                                        char **exclude, struct hash *oldVars, boolean doContentType)
 /* Get cart and cookies and set up error handling.
  * If doContentType, print out Content-type:text/html
  * but don't start writing any html yet.
  * The doMiddleFunction has to call cartHtmlStart(title), and
  * cartHtmlEnd(), as well as writing the body of the HTML.
  * oldVars - those in cart that are overlayed by cgi-vars are
  * put in optional hash oldVars. */