AI Verified

Name

Insert Google Analytics in Header

About

Insert Google Analytics in Header

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Add this to functions.php

Codevault

Clarke-Design

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.clarkedesign.co.uk/

History

Last modified:

26/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

--------------------------------------------------------------------------------------------------------------------------------------------------
Name | Potential vulnerability found : High Entropy String
Line | 8
Code | ( <scriptasyncsrc="https://www.googletagmanager.com/gtag/js?id=UA-1234567")
Code | Line | 8 : <scriptasyncsrc="https://www.googletagmanager.com/gtag/js?id=UA-1234567"

Found 1 vulnerabilities

Insert Google Analytics in Header

 
                    
1// ### Insert Google Analytics in Header
2// ##################################
3add_action('wp_head', 'cwdwp_google_analytics_header');
4function cwdwp_google_analytics_header(){
5 //Close PHP tags
6 ?>
7 <!-- Global site tag (gtag.js) - Google Analytics -->
8 <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1234567"></script>
9 <script>
10 window.dataLayer = window.dataLayer || [];
11 function gtag(){dataLayer.push(arguments);}
12 gtag('js', new Date());
13 
14 gtag('config', 'UA-1234567');
15 </script>
16 <?php //Open PHP tags
17}

0

Comments

  • JF

    9 months ago

    Surely this needs changing as UA has been discomtinued?

Related Snippets

Please see some snippets below related to this snippet..

Tracking - Analytics

AI Verified

1

Google tag added to head

Added: 1 year ago

Last Updated: 1 year ago

Google tag code added to the head of the web site

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

0

Rename Posts to News

Added: 1 year ago

Last Updated: 1 year ago

Posts is a rather general terms. Some clients like to rename this to something more specific like "News".

General

AI Verified

0

Stop P tags

Added: 1 year ago

Last Updated: 1 year ago

Prevent wordpress from automatically adding p tags around everything

Tracking - Analytics

AI Verified

0

Insert Google Analytics in Header

Added: 1 year ago

Last Updated: 1 year ago

Insert Google Analytics in Header