Site Kit not inserting Analytics code into header
Bug Description
It appears that Site Kit did not insert the Google Analytics code into the theme header. Refer to the discussions by me and @ernee in Issue #697
In website: websitesbykts.com, I had been using another analytics plugin, Analytify, and getting long term notices that Analytics was gathering data and to come back. I eventually uninstalled the plugin and installed Site Kit, on 8/22/19.
Steps to reproduce
Here are my contemporaneous notes about the Analytify issue and the installation of Site Kit. I have deleted the details of the codes, permissions, etc. for security.
______________________________________________________Start of Notes __________________ 8/22/19 Google Analytics is not showing any hits to the site. GA says as much and gives instructions to be sure it's set up correctly. GA tag goes into page head for all pages. Here's the tag:
Analytify says that GA was set up, but I don't see the code in the page source. Logout and try to reverify. Don't see any place to put the google code into the plugin.
The support forum has several reports of "not working".
This is not worth the pain, I think. There's a new beta plugin from Google, Google Site Kit, that has several laudatory youtube videos. Download from Google's site, try it.
First: back up with Updraft Plus. Update plugins. Remove Analytify.
Backed up. Update Astra theme and plugins. Site looks ok.
Remove Analytify. Install google-site-kit.zip from file.
get started by creating a client configuration on developers.google.com/web/sitekit
Displays:
Confirm that the below values apply to your WordPress site:
Project Name: Websites by KTS
The title of your new Google Cloud Platform project.
Application Name: Site Kit on https://websitesbykts.com
The name of the app asking for consent, as publicly displayed to authenticating users.
Support Email: [email protected]
The email address shown on the consent screen for user support.
Redirect URI: https://websitesbykts.com?oauth2callback=1
The URI to redirect to after an authenticating user has granted consent.
OAuth Credentials:
{ "web": { "client_id": ".apps.googleusercontent.com", "project_id": "websites-by-kts-", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider__cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_secret": "", "redirect_uris": [ "https://websitesbykts.com?oauth2callback=1" ] } }
End up granting the following permissions: Confirm your choices
[email protected] You are allowing websitesbykts.com to: Associate you with your personal info on Google See your personal info, including any personal info you've made publicly available View your email address View and manage Search Console data for your verified sites Manage the list of sites and domains you control Make sure you trust websitesbykts.com You may be sharing sensitive info with this site or app. Learn about how websitesbykts.com will handle your data by reviewing its terms of service and privacy policies. You can always see or remove access in your Google Account. Learn about the risks
Successfully connected to Search Console. Now connect to Google Analytics.
End up granting the following permissions: Confirm your choices
[email protected] You are allowing websitesbykts.com to: Edit Google Analytics management entities Manage Google Analytics Account users by email address View your Google Analytics data View and manage your Google Analytics data You already gave websitesbykts.com access to: • Associate you with your personal info on Google • See your personal info, including any personal info you've made publicly available • View your email address • View and manage Search Console data for your verified sites • Manage the list of sites and domains you control Make sure you trust websitesbykts.com You may be sharing sensitive info with this site or app. Learn about how websitesbykts.com will handle your data by reviewing its terms of service and privacy policies. You can always see or remove access in your Google Account. Learn about the risks
Now connect PageSpeed Insights. Get API key at https://developers.google.com/web/site-kit/apikey?sitename=Websites%20by%20KTS&siteurl=https://websitesbykts.com
Dashboard reports: Data error in PageSpeed Insights Issue accessing data, please ensure the API key is set correctly. Site Kit Dashboard>Settings says Page Speed is connected.
After a few minutes, it shows up ok. Looked at some results briefly. GA has not finished gathering data. PageSpeed for desktop looks very good, but some suggestions for improvement. For mobile, it needs a little more work and does not score as well.
__________________________________________________ End of Notes __________________________________
Both GA and Site Kit in the dashboard continued to show No Hits or "Acquiring Data, come back later". See website image below:
As of last night, I manually installed the GA snippet in the theme header and things are working.
One area of confusion on my part is that the Search Console results were live, but the Google Analytics results were not.
Screenshots
Additional Context
PHP Version: 7.1.14 OS: Win7 Pro Browser Chrome Portable Plugin Version version 1.0.0-beta.1.0.8 installed. Update to 1.0.0-rc.1. Device: desktop
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
Changelog entry
@Jack-ongithub thanks for opening a new issue and providing these helpful details.
I definitely see the snippet inserted in the header last night.
-
Could you confirm if you're currently seeing Google Analytics data on your dashboard?
-
Site Kit should detect your current snippet. Under Site Kit > Settings > Google Analytics you'll see the following notice indicating it detects the snippet being inserted by another plugin or theme:

Do you see this notice?
- Yes, I see the notice
Looks like Analytics is working. Here's a screenshot with questions.

Thanks for the confirmation @Jack-ongithub ! Glad to hear it is working.
A few items to keep in mind when you update your theme:
-
A manually inserted snippet in the theme's header.php file will most likely be erased on theme update. So using a plugin or perhaps a built-in feature of your theme if available is the best to retain the snippet on the site.
-
You can use Site Kit or any other plugin or theme to insert the snippet, however there should be only one snippet present on your site. To insert the snippet with Site Kit, go to Site Kit > Settings > Google Analytics > Edit , then select Insert snippet and click the Confirm Changes button:

You should then see an update to the notice that the Snippet is inserted (by Site Kit):

In regards to your question about the All Traffic dashboard, 1. direct is an item on an ordered list not a count.
The snippet was initially inserted into the theme's header.php file. The next day I made a child theme and am now using it.
@ernee I don't understand your closing this. I thought the issue you wanted to address was whether / why didn't Site Kit install the code snippet in the first place?
@Jack-ongithub sorry for the delayed reply. You can use the method you are currently using or Site Kit to connect Analytics. Site Kit will still display Analytics data which was the original issue and it is is resolved hence why I closed the issue. Did you want to use Site Kit instead to insert the snippet? As mentioned, it would require that you remove the manually inserted snippet as you cannot have both that and Site Kit's on the site. Then you can insert the snippet from the settings area (see number 2 above). With that said, what you are currently doing is totally acceptable.