Adding Google Analytics without a Plugin

There are a few different ways to add your Google Analytics tracking ID to your WordPress site. This method results in inserting the tracking code before the closing body tag.

Where does this go?

Replace the function’s prefix with the appropriate theme prefix or naming conventions you’re following and insert in your theme’s functions.php (or equivalent) file. Copy and paste your account-specific snippet within the script tags so your actual tracking ID is applied.

add_action( 'wp_footer', 'prefix_google_analytics' );
 * Add Google Analytics Tracking.
function prefix_google_analytics() {
	// Hook into the footer.
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

		ga('create', 'YOUR-GOOGLE-TRACKING-ID-HERE', 'auto');
		ga('send', 'pageview');

Once this code is added to your live site, it will likely take a day or so to display the data within your account.

Additional Reading:

Leave a Reply

Your email address will not be published. Required fields are marked *