Google Analytics

hi good night
Can help me
I want to add code analytics in my theme roots.
how can?

Use the following plugin:

Provides a series of additional options other than just basic analytics.

Roots has Google Analytics support built into the theme. Simply add your Universal Analytics Tracking ID to the /lib/config.php file as shown here.

chriscarr thanks for you comment.
I put my Analytics ID UA-XXXXXXXX-2 in this line but don’t work.

1 Like

As Chris said, it only supports the relatively new Universal Analytics IDs. Double check that you are using the correct ID.

I think the format is UA-XXXXX-XX.

1 Like

Thanks for the info, I wish I would have known this, or seen this before I launched - is it in the README and I missed it that Roots supports only the Universal Analyrics?

I added my Google Analytics ID of UA-XXXXXXX-X, and have lost two months of Analytics because I had the older formatted ID. Also - you’ll have to upgrade your Analytics to the Universal Analytics in your Google Profile too before they’ll give you the new Universal ID number.

As @Foxaii suggested, check the format of your tracking code and double check it’s working with Google Analytics Real Time Beta feature.

THEN triple check before launch. I’ve had this happen to me a few times and it’s pretty difficult to explain to a client where all that tracking data went only after your realize it’s not working.

1 Like

Thanks @emaildano, I definitly learned my lesson on this and will be checking each site on launch with the real-time tools, excellent idea, thanks for the tips!

Hi, PLEASE mention in the lib/config.php comments that :
the google analytics tracking code won’t show if you are logged in as Admin !
By the way, this trick is really clever :smiley:

1 Like

seconds to that - spent a few frustrating hours trying to find out why this isn’t working!

@mecanographik I’m glad you said this because I, too, would have spent too much time looking for this to verify it’s working!

Is Google Analytics support not present in Sage 9 (9.0.0-alpha.4)? I’m not seeing it anywhere. Maybe the method was just altered. :confused:

It was moved to the Soil plugin

Okay thanks @vdrnn. I knew that but I guess I’m just confused how to implement it because I think there used to be the add_theme_support in lib/setup.php to add your Google Analytics ID.

In soil/modules/google-analytics.php the comment says:

 * Google Analytics snippet from HTML5 Boilerplate
 * Cookie domain is 'auto' configured. See:
 * You can enable/disable this feature in functions.php (or lib/setup.php if you're using Sage):
 * add_theme_support('soil-google-analytics', 'UA-XXXXX-Y', 'wp_footer');

So do I need to add add_theme_support('soil-google-analytics', 'UA-XXXXX-Y', 'wp_footer'); to sage/src/setup.php manually?

Yes, exactly! :slight_smile:

Just add it into the after_setup_theme action after the other add_theme_support functions.


I can confirm that with Sage 9 you have to add add_theme_support('soil-google-analytics', 'UA-XXXXX-Y')in your setup.php after all the other add_theme_support calls that are already there.

Also, perhaps it’s obvious but for me it wasn’t:

for this to work you have to install the Soil plugin manually!

This thread covers this embarrassing ignorance from me: Google Analytics via Soil: GA code not appearing anywhere - #15 by trainoasis