Adding Google Analytics script

Post

Posted
Rating:
#8527 (In Topic #2135)
On the Google Analytics page/site, Google allows a way to help track website usage. They do this by creating some code that they ask the webmaster to insert in the HEAD area of the HTML. In the case of Composr, it would mean editing HTML_HEAD.tpl to add the following script (some of it is chopped out, but you'll get the idea)…

Code (javascript)

window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-ZN****');
I think I'm missing something, because in that case, I'd have to edit every new version of Composr that came out.

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? :)

Post

Posted
Rating:
#8528
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)?

Post

Posted
Rating:
#8529

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)?

Oh sure, it's Collapse.Forum

Post

Posted
Rating:
#8530
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.

Post

Posted
Rating:
#8531

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.

Excellent! Will do.

Post

Posted
Rating:
#8535
Hello,

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.
0 guests and 0 members have recently viewed this.