# Google Analytics without Soil

**URL:** https://discourse.roots.io/t/google-analytics-without-soil/5703
**Category:** sage
**Created:** 2016-01-15T23:00:35Z
**Posts:** 3

## Post 1 by @svdb — 2016-01-15T23:00:35Z

Hi all,

Can we still add our Google Analytics tracking code in Sage like we used to do in Roots?  
What is the recommended way? I am not using the Soil plugin.

Regards,  
Steven

---

## Post 2 by @kalenjohnson — 2016-01-15T23:22:35Z

You have a couple options:

- Use Soil
- Get the code that was in Roots before. It’s all in the git history
- Add Google Analytics according to their website
- Use any of the multitude of WP plugins that add GA

---

## Post 3 by @willthemoor — 2016-01-17T10:03:45Z

Grab the code from [HTML5 Boilerplate](https://github.com/h5bp/html5-boilerplate/blob/master/src/index.html) and stick it in your base.php.

If you want a repeatable way to do it in your own sage fork or something where you only need to include the GA UA ID, go the old Roots route: wrap that HTML5BP `<script>` code in a php function, make the “UA-XXXXX-X” bit a PHP CONSTANT you set somewhere and attach it to `wp_footer`

```
//in some file, even wp-config.php
 define('GOOGLE_ID', 'UA-123456-7');

 //and in config.php or setup.php
 function includeGA(){ ?>
     //<script> from boilerplate here
<?php } ?>
add_action('wp_footer', currentNAMESPACE .\'includeGA', 10);
```

I’ve taken to using CMB2 to make a site options form within the admin. I include a field for it there and pull that in.
