There are several different ways to add a Google Analytics tracking code to your Uncode-based website.
Theme Options
To install Google Analytics please create a new tracking code from the Google Analytics website, copy the tracking code ID and paste in the dedicated fields in Theme Options. You can choose to enter your tracking code in the fields:
- Theme Options → CSS/JS → JavaScript
- Theme Options → CSS/JS → Tracking (possible exclusion with the Privacy Plugin)
These fields are very similar and you can choose which one to use based on your needs. The difference is that if you use the Tracking field it's possible, combined with the Privacy Plugin, to exclude the codes until the explicit consent of the user. We invite you to visit the dedicated Privacy Plugin documentation page for more information. In case of need of compliance with the GDPR, our suggestion is to use Google Analytics with the Anonimyze IP option in the JavaScript field and insert any other more aggressive tracking codes that do not provide anonymize options in the Tracking field (in this way the Tracking codes will be fired only after the user's consent).
Google Analytics Universal
This is an example of Google Analytics Universal tracking code, note that you need to replace 'UA-XXXXXXXX' with your Google Analytics ID:
<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', 'UA-XXXXXXXX', 'auto'); ga('send', 'pageview'); </script>
The property ID may represent measurement for different Google products, including a Universal Analytics property ("UA-XXXXXXXX"), a Google Analytics 4 property ("G-XXXXXXXX"), Google Ads ("AW-XXXXXXXX") or Floodlight ("DC-XXXXXXXX").
Google Analytics Anonymize IP (GDPR)
Please note that to improve compliance with the GDRP you can take advantage of the anonymized IP function, please note the 'anonymizeIp' code before the 'ga('send', 'pageview');', ex:
<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', 'UA-XXXXXXXX', 'auto'); ga('set', 'anonymizeIp', true); ga('send', 'pageview'); </script>
Tag Manager
To use a tracking Tag Manager you can use a dedicated plugin, or alternatively use these tracking codes in the functions.php file of your Child Theme:
function uncode_child_custom_tag_manager_head_code() { ?> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXX');</script> <!-- End Google Tag Manager --> <?php } add_action( 'wp_head', 'uncode_child_custom_tag_manager_head_code' ); function uncode_child_custom_tag_manager_body_code() { ?> <!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) --> <?php } add_action( 'before', 'uncode_child_custom_tag_manager_body_code' );
Plugins
Alternatively, you can use some free WordPress plugins to add the tracking code to your Uncode-based website. There are other plugins that can add the tracking code to your website that are not mentioned here. This doesn't mean they are not compatible with Uncode. Just try what you find will work for you best:
Comments
0 comments
Article is closed for comments.