Adding Google Analytics script
Posted
#8527
(In Topic #2135)
Code (javascript)
window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-ZN****');
There is is an option to add a
Google Analytics Web Property ID in Site Options -> Analytics, but after adding the Google Analytics gtag ID, opening the site, and checking Google's site for evidence that Google can see the gtag script, Google says it can't see the script. On checking the source of index.php, I don't see the gtag mentioned, either.
The docs show hot to set up Google Analytics (kinda) on the Google side, but I don't find anything mentioning how to inject this script into the HEAD of every page of the site.
What'd I miss?
Posted
Are you comfortable sharing the URL to the site so I can take a look and see if Composr is failing to inject anything entirely, or if Composr is actually injecting something (but maybe it's outdated or Google can't see it)?
Posted
PDStig said
Hello,
Are you comfortable sharing the URL to the site so I can take a look and see if Composr is failing to inject anything entirely, or if Composr is actually injecting something (but maybe it's outdated or Google can't see it)?
From “Post #8528”, 29th Jul 2025
Oh sure, it's Collapse.Forum
Posted
I've identified the issue; please report to the tracker so I can fix it and you'll get credit.
Actually, two separate tracker issues need reported…
—1—
Title: google-analytics.com not on list of trusted CSP sites
Description: google-analytics.com needs to be added to the list of trusted CSP sites when Google Analytics is active. Otherwise, the script gets blocked.
—2—
Title: Changing any public config options should trigger template cache flush
Description: Because public config values are stored in JavaScript configOptionsJson variable through a Tempcode symbol, changing any public configuration options should trigger an automatic template cache flush so this value is updated and is not stale.
Posted
PDStig said
Thanks!
I've identified the issue; please report to the tracker so I can fix it and you'll get credit.
Actually, two separate tracker issues need reported…
—1—
Title: google-analytics.com not on list of trusted CSP sites
Description: google-analytics.com needs to be added to the list of trusted CSP sites when Google Analytics is active. Otherwise, the script gets blocked.
—2—
Title: Changing any public config options should trigger template cache flush
Description: Because public config values are stored in JavaScript configOptionsJson variable through a Tempcode symbol, changing any public configuration options should trigger an automatic template cache flush so this value is updated and is not stale.
From “Post #8530”, 29th Jul 2025
Excellent! Will do.
Posted
These bugs are fixed, but I just realized Composr is using Analytics v3 which was shut down. It does not support analytics / Google Tag Manager v4.
This is not something officially supported by Composr, so if you'd like Analytics v4 support / Google Tag Manager, please contact/hire me or another developer and it can be done. Given my financial situation, it is too much of a time commitment to implement without funding.
1 guest and 0 members have recently viewed this.