2837ed0c110b12b4549d82ffaa4f154bdb2a09c4 max Mon Jan 8 04:51:09 2024 -0800 adding GA4 code to second code that generated <HEAD>, refs #30725 diff --git src/lib/htmshell.c src/lib/htmshell.c index 2e0b3b9..54590fc 100644 --- src/lib/htmshell.c +++ src/lib/htmshell.c @@ -809,30 +809,36 @@ } static char *htmlFormClass = NULL; void htmlSetFormClass(char *formClass) /* Set class in the BODY part. */ { htmlFormClass = formClass; } void htmlSetGa4Key(char *key) /* Set GA4 key. Needs to be called before htmlStart or htmShell. */ { analyticsKey = key; } +void htmlPrintAnalyticsLink(FILE *f) { +/* print the link to the analytics javascript file in the html header. (Analytics 4 wants the javascript file referenced in the header) */ +if (analyticsKey) + fprintf(f, "<script async src=\"https://www.googletagmanager.com/gtag/js?id=%s\"></script>\n", analyticsKey); +} + void htmlSetStyleTheme(char *style) /* Set theme style. Needs to be called before htmlStart or htmShell. */ { htmlStyleTheme = style; } static char *htmlBackground = NULL; void htmlSetBackground(char *imageFile) /* Set background - needs to be called before htmlStart * or htmShell. */ { htmlBackground = imageFile; } @@ -1147,32 +1153,33 @@ // CSP header generateCspMetaHeader(f); fputs(head, f); htmlFprintf(f,"<TITLE>%s</TITLE>\n", title); if (endsWith(title,"Login - UCSC Genome Browser")) fprintf(f,"\t<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;CHARSET=iso-8859-1\">\n"); fprintf(f, "\t<META http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n"); if (htmlStyle != NULL) fputs(htmlStyle, f); if (htmlStyleSheet != NULL) fprintf(f,"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\">\n", htmlStyleSheet); if (htmlStyleTheme != NULL) fputs(htmlStyleTheme, f); -if (analyticsKey) - fprintf(f, "<script async src=\"https://www.googletagmanager.com/gtag/js?id=%s\"></script>\n", analyticsKey); + + +htmlPrintAnalyticsLink(f); fputs("</HEAD>\n\n",f); printBodyTag(f); htmlWarnBoxSetup(f); } void htmlStart(char *title) /* Write the start of an html from CGI */ { puts("Content-Type:text/html"); puts("\n"); _htmStartWithHead(stdout, "", title, TRUE, 1); }