Trackers GA4 ga.js Example {{ ga4}}

Documentation for UBC Library GA4 Google Analytics Tracker(s)

Your application will contain environment variables GA4_ID and Analytic in your .env file and in the dependencies.php allowing the tracker.js on cdn server to run.

Below is an example of the dependencies.php

$twigGlobals = [ 'analytics' => $_ENV['ANALYTICS'] ?? false, 'ga4' => $_ENV['GA4_ID'] ?? "GA4_ID" ];

the code required for google analytics and render the code on your site header.

You can turn off google analytics by adding false to your Analytics enviroment variable

This script uses the environment variables from the application
  

<script src="https://cdn.library.ubc.ca/ga4/js/trackers-ga4.js"
        data-id="lib-ga-trackers"
        tracker_ga4_1=  {{ga4}}
        data-tracker2domain="  {{ base_url}} ">
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id="  {{ga4}} " ?>"></script>