Can I add my existing html homepage google analytics code into new wordpress homepage? - wordpress

We are having a html website whose homepage and other few pages has google analytics code and keywords. Now we have created a new homepage on wordpress which will be our future homepage. So my question is can I use my existing homepage GA code into my new wordpress homepage? If yes then how? We don't want to lose our previous tracking data at any cost.
How can use it? Please Help.
TIA.

Yes, you can use your existing google analytics code by using WordPress plugins.
There are many plugins in WordPress which provides ability to integrate your google analytics code to your site and all pages dynamically and also display you a complete tracking reports as well.
here is one plugin link for your reference please check it.
https://wordpress.org/plugins/googleanalytics/
There are lot's of other plugins as well you can simply check out in WordPress plugins repository.
=> Also you can add your google analytics code programmatic as well.
Please copy below code and paste it into your activated themes functions.php file at the end of the file.
function add_google_analytics_code_to_pages(){
?>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-ADD YOU GOOGLE ANALYTICS ID HERE', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<?php
}
add_action("wp_head","add_google_analytics_code_to_pages");
Just add your google analytics tracking id into about script.
Replace your tracking id instead of this code.
'UA-ADD YOU GOOGLE ANALYTICS ID HERE'

Unless I am missing something here, sure!
All you have to do is enter your Google Tracking code inside the <head> tags, within the header.php template file. Ideally, just before the closing </head> tag.
By inserting your Google Tracking code, within the header.php template file, every WordPress page will be tracked.
Your header.php template file will typically be found within the following directory path:
wp-content > themes > theme-name
If you are not the theme author, don't forget to create a Child Theme. You will then need to insert the appropriate header.php template file within said Child Theme.
Google Tag Assistance:
For the most part, the above should resolve your problem. You can check whether the Tracking code has been correctly installed by:
Reviewing the code within the Source Code
Installing Google Tag Assistance within Chrome
Exception:
Again, the above should be enough to resolve your issue. Some themes however, do create different headers, for different pages of the site. For example: An eCommerce site may want a different header on their shop pages to their Blog Pages. To achieve this, header template files, such as below would be created:
header-shop.php
header-blog.php
header-ppc.php
To then 'call' each header, the following example PHP entry would be placed within the relevant template file(s):
<?php get_header( 'shop' ); ?>
'shop' being whatever word appends the header- file name. In this case, 'shop', 'blog' and 'ppc'.
You do not need to worry much about this. All you need to do, is head into the root of your theme as follows:
wp-content > themes > theme-name
Look for any files with begin with header- and ensure they contain the Google Tracking code.
In the event you are using a Child Theme, simply copy the header- files over to the root of your Child Theme first and then modify accordingly.
Hope this helps.

Related

How to add a separate Analytics for each website page in Wordpress

We have a WordPress installation that has locations as separate pages.
For example: mysite.com/colorado and mysite.com/alabama
We need separate google analytics for each of these as well as 1 for all of mysite.com.
Is there a way to do this with a WordPress plugin(s) or will we need to hand code some things?
Thanks in advance!
If I'm not mistaken, Google Analytics lets you view your analytics in a breakdown like that. That said, if you do need individual scripts, it would be relatively easy to program in. There may be some plugins that do this, but I'm not aware of any in particular, though a cursory glance showed plugins like Header and Footer Scripts that allow you to add scripts on a page by page basis.
Some themes also allow you to add SEO/Script settings per page/post. If that's the case, you can just open up each page and dump each script tag in the "header scripts" or similar section, and call it good. (Genesis is an example of a theme that does this).
If not, programming this would be relatively straight forward. I'd do it something like this:
add_action( 'wp_head', 'display_analytics_by_page', 1 );
function display_analytics_by_page(){
// Default Script Code with individual UA codes replaced
$script = '<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=[UA-CODE]"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(\'js\', new Date());
gtag(\'config\', \'[UA-CODE]\');
</script>';
// Array of UA codes by state
$codes = array(
'Alabama' => 'UA-123456789-1',
'Oregon' => 'UA-987654542-3',
'Vermont' => 'UA-000000000-0'
);
// Get title of this page
$title = get_the_title();
// If this page title exists in the codes array, swap placeholder and echo it.
if( isset($codes[$title]) ){
echo str_replace( '[UA-CODE]', $codes[$title], $script );
}
}
I commented along the way, but the gist is to put in the "default" script, but pull out the UA code. This will only work if you need the same exact script code in each one, otherwise you'll have to add each script to the $codes array instead.
Then create an array of the UA Codes (or full scripts if needed), keyed by the page title.
Then check the page title, and if that exists, pull that code in and echo it. This is run on the wp_head hook, so you just need to put this code in your functions.php (or similar) file.
If you want to go easy with no-coding, then go with a plugin. Jump to Plugins > Add New and Search for Google Analytics in the search box. Install the plugin named Google Analytics for WordPress (Formerly GADWP). Activate and connect the plugin with your Google Analytics property. When all is done, you will see a new tab beside your post's title. See a screenshot here.
And if you want the net analytics for the whole web site then head to your admin dashboard. A new widget will appear there with the analytics.
Documentation for the plugin can be found here.
I hope it helps.
I'm curious why you need a separate GA account for all the locations? Common practice in this scenario would be:
Use 1 account
Create 1 GA view for the entire domain
Create +1 view for each location by filtering traffic based on the URL
If the different accounts are related to limiting user access, know that you can grant user access based on each property view.

How to find out where a script-tag has been defined in the wordpress-header?

I have to work in a wordpress project of a former colleague. But I cannot figure out how he added an link-address to a script into the header of each page. After a global search, the link-address was found inside the sql dump of the wordpress project. I could not find any plugin he might have used. I would like to change the link-address. Any idea, how he added it?
<script src="http://custom-link/page.js" type="text/javascript" defer=""></script>
It was added by the wordpress plugin divi builder.
Divi Theme Options
To add a code to every page navigate to Divi Theme Options > Integration tab.
Make sure the “Enable header code” option is checked, and paste your code below.

Can I remove the JSON-LD schema that Yoast adds to my WordPress site?

I would like to remove the JSON-LD schema that Yoast applies to my WordPress site so that I can add my own. I have already added my own, and Google Structured Data Testing says that it is OK, but basically I have 3 separate JSON-LD schemas instead of two because of Yoast.
You can see what I mean here: https://search.google.com/structured-data/testing-tool/u/0/#url=http%3A%2F%2Fwww.yogabearpc.com
Yoast has added the WebSite schema and it seems unnecessary or even damaging?
I wanted to disable this because of the sitelinks searchbox and the fact that I don't have a search function that works globally, just on the blog. Having the search box enabled for me would have undesirable effects.
The easier option may just be to prevent Google using the sitelinks searchbox without having to touch the functions files. You can prevent Google using sitelinks searchbox on your site by using the following meta:
<meta name="google" content="nositelinkssearchbox" />
If you want to disable Yoast's JSON-LD all together then here's a snippet from my blog and the code I use on my site:
SOURCE
How to disable Yoast SEO Schema JSON-LD completely
function bybe_remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
Login to your WordPress dashboard and head over to the editor
within the tab menu appearance, find your functions file (normally
named functions.php) and add the code below just before the PHP tag is
closed at the bottom.
Simplest way to completely disable the Yoast SEO schema JSON-LD
Add this line to functions.php file:
add_filter( 'wpseo_json_ld_output', '__return_empty_array' );
Source
If you want to disable just Organization or just Website, add this to your theme's functions.php file:
function bybe_remove_yoast_json($data){
if ( (isset($data['#type'])) && ($data['#type'] == 'Organization') ) {
$data = array();
}
return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);
Unless the data Yoast produces is wrong, there is no harm in having it. Quite the contrary, having more structured data is better than having less.
If having it is "unnecessary" depends on your definition of what is necessary. Some consumers might be interested in it, others not.
My guess is that Yoast adds a WebSite entity because of Google’s sitelinks searchbox rich snippet result, which allows Google users to search your site directly from the Google search result.

Where is the metadata robots no index, no follow in my wordpress site comming from?

This is my wordpress site: linearedge.com
If you check the source code you will find:
<meta content="noindex,nofollow" name="robots">
I'm not using ANY SEO plugin, so, where is this coming from? I also checked my header.php and that line isn't there.
Thanks.
Its getting put in there by the call to wp_head() in the header.php file of your theme. Check your Search Engine Visibility setting (Settings > Reading). Make sure that box is unchecked.

Wordpress Sign-ups Using GA Goal Tracking

I'm trying to use GA Tracking to Track Wordpress Sign-ups on my site. I'm assuming I need to use Goal Tracking and NOT Event tracking for this. I tried setting up goal tracking but it's not working. I am not using any GA plugins like Yoast, etc.
I can't get this to work with Wordpress:
I set my Goal URL to: /wp-login.php?checkemail=registered (URL landing page for sign-ups)
Match Type: "Exact Match"
No Goal Funnel was set.
GA is not tracking any of my sign-ups. What I am doing wrong here? My site is www.StreetofWalls.com if you would like to test.
The script that loads google-analytics isn't on the login page, so you're not getting any of the /wp-login.php?checkemail=registered pageviews sent back to google.
Put this on your wp-login.php page
<script type='text/javascript' src='http://www.streetofwalls.com/wp-content/themes/sow3/js/google-analytics.js'></script>
While TomFuertes's answer will work, it is not good to modify core WordPress files like wp-login.php. Updates to WordPress will overwrite any changes that you make and avoiding WordPress updates is a very bad idea.
I recommend adding the code using the login_head hook in your functions.php file:
function add_ga_to_login_page(){
echo '<script>';
echo 'GA TRACKING CODE HERE';
echo '</script>';
}
add_action('login_head', 'add_ga_to_login_page');

Resources