[Koha] Google Analytics 4 and Koha 22.05, help needed

Eric Phetteplace ephetteplace at cca.edu
Wed Nov 16 12:01:05 NZDT 2022


Just adding that you can safely ignore OPACUserJS warnings if you know your
script works; they do not prevent you from saving the field's value. I
minify our OPACUserJS so it shows dozens of errors, but the code still
functions. For something like this where you need to inject another script
tag, you can do that in JavaScript first and then continue with the
window.dataLayer stuff e.g.

let d =d document
    , s = d.createElement('script')
    , t = d.getElementsByTagName('script')[0];
s.async = 1
s.src = 'https://www.googletagmanager.com/gtag/js?id={{your ID}}'
t.parentNode.insertBefore(s, t)

Best,

ERIC PHETTEPLACE Systems Librarian, Libraries (he/him)

ephetteplace at cca.edu | o 510.594.3660 (cca)


*CCA is situated on the traditional unceded lands of the **Chochenyo and
Ramaytush Ohlone** peoples.*

Black-owned bookstores in Oakland: Ashay by the Bay
<https://ashaybythebay.com/>, Marcus Books
<https://www.facebook.com/marcus.books/>

:(){ :|: & };:


On Tue, Nov 15, 2022 at 9:35 AM Elaine Bradtke <eb at efdss.org> wrote:

> We haven't been using Google Analytics on Koha, but we thought we would try
> it to see if it throws up any useful data. They're switching to a new
> system (Analytics 4). I thought I'd start there, but I haven't had any
> success in implementing it.  Has anyone done this in 22.05 and if so could
> you help me out? I know nothing about JavaScript.
>
> Here's what I've tried so far:
> I looked at Koha Geek's tip where it suggests we paste the site tag into
> opaccredits, but this doesn't seem to be System preference anymore
> http://kohageek.blogspot.com/2019/01/google-analytics-koha.html
>
>  From Bywater (
>
> https://bywatersolutions.com/education/setting-up-google-analytics-with-koha
> ) – add the following to opacuserjs – change the track id to your Google ID
>
>
> //Begin Google Analytics script
>
>
>
> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
>
> (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
> Date();a=s.createElement(o),
>
>
> m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
>
> })(window,document,'script','https://www.google-analytics.com/analytics.js
> ','ga');
>
>
> ga('create', 'trackID', 'auto');
>
> ga('send', 'pageview');
>
>
> //End Google Analytics script
>
>
> This throws up syntax errors about missing semicolons, and 'expected an
> assignment of function call and instead saw an expression'
>
>
>
> From new Google analytics – (our ID is xed out) - this throws up error
> messages about identifiers, operators and an unrecoverable syntax error.
>
>
> <!-- Google tag (gtag.js) -->
>
> <script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXX
> "></script>
>
> <script>
>
> window.dataLayer = window.dataLayer || [];
>
> function gtag(){dataLayer.push(arguments);}
>
> gtag('js', new Date());
>
>
> gtag('config', 'XXXXXXX');
>
> </script>
>
>
> Thanks for any help you can offer
>
> Elaine Bradtke
> VWML <https://www.vwml.org>
> English Folk Dance and Song Society <https://www.efdss.org>
> Cecil Sharp House, 2 Regent's Park Road, London NW1 7AY
> Tel    +44 (0) 20 7485 2206 (This number is for the English Folk Dance and
> Song Society in London, England. If you wish to phone me personally, send
> an e-mail first. I work off site)
> --------------------------------------------------------------------------
> Registered Company No. 297142
> Charity Registered in England and Wales No. 305999
> _______________________________________________
>
> Koha mailing list  http://koha-community.org
> Koha at lists.katipo.co.nz
> Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
>


More information about the Koha mailing list