Insert Google Analytics into theme header difficulty

Hi Folks,

I am having trouble with modifying the X theme header. I had a previous ticket some time ago and gave up:

https://theme.co/apex/forum/t/install-adsense-code-where-exactly-in-header/20893

Now I would like another try. Much appreciated

**Unable to communicate back with the site to check for fatal errors so the PHP change was rverted,

Hello Matthew,

if you want to add Google Analytics tracking to your site, you actually do not need to touch the files as there is a Google Analytics plugins that comes bundled with X which you can use instead.

Hope this helps.

Hi Jade,

I already have that installed and activated.

Here is from google:
The AdWords ad destination URL https://www.pmhnpexam.com from the AdWords account XXXXXX has significantly more AdWords clicks than Google Analytics sessions. AdWords clicks and Google Analytics sessions should not differ greatly. However, your ad sessions may be inaccurate if your site is not configured correctly.

Moreover, if sessions are not being correctly attributed to your AdWords campaigns, your AdWords reports won’t be accurate.

A number of things can cause clicks/sessions discrepancies.

In this case, the landing page is not on any of the hostnames tracked by this web property:
(not enough sessions)
Double-check whether the hostname this URL is on should be tracked by this web property. If this is expected, you can safely ignore this notification. If not, then make sure the URL has the Google Analytics tracking code with this property’s tracking ID (UA-XXXXXX).

Last detected: Nov 20, 2018 8:16:45 AM

Hello Matthew,

Please disable Google Analytics plugins as there is a bug in this extension for the moment. I would recommend that you use a different plugin instead. If you want to edit the header, you are editing the wrong file. We have a different templating system which is why you are seeing wp-header.php differently. If you want to add some custom contents into the header, it is best that you install “Insert Headers and Footers” plugin (https://wordpress.org/plugins/insert-headers-and-footers/). Once installed, you can go to Settings > Insert Headers and Footers and then insert the GA code in the headers section. The plugin will do the rest and integrate the GA code in the theme’s header. No template edits or even a child theme is required to do it.

Hope this helps.

Hi RueNel,

I have installed.“Insert Headers and Footers” plugin. Nothing immediately has changed --although at least it let me save the content. Does it usually take a few hours to see a change?

Ty for your help

Hello Matthew,

It would take at least 24 hours for Google to display new stats for your site. I guess you might need to ask Google to re index your site again.

https://support.google.com/analytics/answer/1008083?hl=en
https://support.google.com/analytics/answer/1009683?hl=en

https://searchenginewatch.com/sew/how-to/2198245/how-to-force-google-to-recrawl-your-site, https://neilpatel.com/blog/google-index/

Hope this helps.

“No Hits…Property is not receiving hits”

All site maps were accepted. Any other thoughts? ( I get about 200 visitors a day to the site)

Hey Matthew,

If the analytics code was added properly in your site which you can tell if you view the source code, the problem could be in your configuration of your analytics account.

The theme also has no connection to this setup so I’d recommend that you consult with a Google Analytics expert to diagnose the issue in your site.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Hello Matthew,

Do you need to add Adsense code in the header? Is that is the case, please do not place it in header.php file. If you need to add any code for the header, please do this instead once you have your child theme active and ready:

  1. Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
  2. Insert the following code into that new file
<?php

// =============================================================================
// VIEWS/GLOBAL/_HEADER.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site and includes the <head>.
// =============================================================================

?>

<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div id="x-root" class="x-root">

    <?php do_action( 'x_before_site_begin' ); ?>

    <div id="top" class="site">

    <?php do_action( 'x_after_site_begin' ); ?>
  1. Save the file named as _header.php
  2. Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/legacy/cranium/headers/views/gloibal/ or wp-content/themes/pro-child/framework/legacy/cranium/headers/views/gloibal/ if you are using Pro theme.

Off course you will need to create the folder path since it does not exist in your child theme yet.

Please let us know how it goes.