Last active
July 11, 2020 17:22
-
-
Save deeman/8e44babf91cd3a57731d640b5cd4226e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: WordPress Simple Google Analytics Plugin | |
| Description: Lägger till Google Analytics-kod i <head> eller <footer> genom WordPress-hook | |
| * Version: 1.0 | |
| * Author: D. Andersson | |
| * Author URI: https://dandersson.nu | |
| */ | |
| defined( 'ABSPATH' ) or exit; | |
| function da_google_analytics() { ?> | |
| <!-- Global site tag (gtag.js) - Google Analytics --> | |
| <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXXX-X"></script> | |
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'UA-XXXXXXXXX-X'); | |
| </script> | |
| <?php } | |
| add_action( 'wp_head', 'da_google_analytics', 10 ); | |
| echo $analytics; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If needed, you can set it use footer by changing line 23 to
add_action( 'wp_footer', 'da_google_analytics', 10 );