How to Track WordPress Login, Register and Dashboard Activity with Google Analytics

If you have a multi-author blog or a forum or some membership site based on WordPress. Then, you might like to add Google Analytics to WordPress Login, Register or even dashboard. It will help you to understand better about your users’ requirement and help you to how they are using your site.

Google Analytics on WordPress

Another good thing about this article is there is no need of any plugin. And we can easily add Google Analytics to WordPress Login and Register pages or even WordPress Dashboard. Now proceed to next.

If you are using a site specific plugin then add the following code to the plugin else add these codes to your active theme (or child theme) functions file. If you are absolute beginner then you may locate these files here.

Go to WordPress Dashboard –> Appearance –> Editor –> Theme Functions (functions.php)

Add Google Analytics code to WordPress login and register page

This is really easy, simply copy the following code and replace the line <!-- Your Analytics Code Here --> with your actual Google analytics tracking code.

add_action( 'login_head', 'synt_ga_login_page');
function synt_ga_login_page() { ?>
    <!-- Your Analytics Code Here -->
<?php }

This will add your analytics code to WordPress login, register and forget password page.

Track WordPress Dashboard with Google Analytics

Also, If you want to track WordPress Dashboard activities then add the following code.

add_action( 'admin_head', 'synth_admin_head_script' );
function synth_admin_head_script() {
  if ( !is_super_admin() || !is_admin() ) { ?>
    <!-- Your Analytics Code Here -->
 <?php } }

As you see, there is a if condition in the code snippet. If will filter super admins and admin of your WordPress. You may also customize users based on their roles and capabilities.

If you are going to make any change in the above code (other than adding google analytics code) then test your code on a test server. Otherwise, it may potentially break your site.

If you have any problem or have any suggestion leave a comment below. If you liked this article, please share with your friends.

How to add Google Analytics to WordPress sites

GoogleAnalytics

Google Analytics is a fabulous analytics tool enabled on more than 10 million websites across the globe. Here we will add Google Analytics to WordPress site. Obviously, we will need a Google Account first. Here I will skip this because most of us already have a GMail or Adsense Account or even an account associated to Android Phone. So going to straight to Google Analytics Sign up page.

Important: If you do not have Google account and Google is forcing you to create an email id. Then you may directly go to google.com/analytics and start signup process for Google Analytics with your existing email address. You may also use your Google Apps account to sign up Analytics.

Sign Up Google Analytics Account:

Once you have logged in to Google Account you may sign up Google Analytics account. The Analytics signup page will be something like this. Add account name, site name, website url, industry category and time-zone for your reporting. Don’t worry about any discrepancy, you may change all these information later.

GA-setup

After filling the information required proceed to accept terms of the services and sign up. If everything goes right you will get your tracking code and Google Analytics account instantly. Your Analytics account id will be something like “UA-47713692-1” and some JavaScript code something like below. Some WordPress themes including thesis theme framework have built-in functionality where we have to enter the tracking id only. For rest of the themes we will need the entire script.

ga-tracking-code

Adding Google Analytics code to WordPress site:

Once we have Google Analytics code we will now add this tracking code to the WordPress site. There are a few approaches to do that.

  1. Add the code using wp_head or wp_footer hook.
  2. Directly add the code to theme file (by modifying header.php or footer.php)
  3. Using a plugin or theme feature

Add the code using wp_head or wp_footer hook.

You may add a few lines of code to theme’s functions.php  file.

/**
* How to add Google Analytics to WordPress by @_Anand_Kumar
* Tutorial link http://blogsynthesis.com/?p=1435
**/
add_action( 'wp_head', 'synth_google_analytics');
function synth_google_analytics() { ?>
<!-- REPLACE THIS LINE WITH GOOGLE ANALYTICS CODE -->
<?php }

Do not forget to replace <!-- REPLACE THIS LINE WITH GOOGLE ANALYTICS CODE --> with your actual Google analytics code.

That’s all. Your WordPress site will, now, be tracked by Google Analytics.

Directly add the code to theme file (by modifying header.php or footer.php)

You may copy and place the obtained code to header.php file. Here, we will have to find the closing head tag ie </head>. Once you find the code place the Analytics code just above it.

This method is do not works will all themes because many themes do not have header.php or the theme developer do not suggest to modify the code directly to theme file.

Add Google Analytics to WordPress using theme feature / option.

A lot of themes (including Genesis, Thesis) have options to hook some code to header and/or footer. You may use this feature. This is one of the easy (and safe) way to add scripts to your sites.

  • Genesis user may add the code to “Header and Footer script” under Genesis Setting menu.
  • Thesis 2 user may navigate to Thesis >> Site >> Google Analytics (just place the id, which will be like UA-123456-1. See the highlighted image 2) OR add the whole tracking code under Thesis >> Site >> Tracking Script.
  • There are a few plugin who offers some features add the code at ease.

Now if you might ask which method I prefer! Frankly I will prefer either method one or three (if my theme has such feature.)

Here are a few reasons behind it.

  • Using a plugin for everything sucks. It will slow down the speed of your site and ultimately provide bad user experience.
  • If the theme has such functionality then we may add a number of scripts using just one hook.
  • Modifying Theme file will be hard to maintain at some point in future.
  • An intermediate (or even you) may opt for a site specific plugin. This will be best option to add cross theme functionally. Here you may find more information about site specific plugin. Note: Any of the above three method will be enough for this purpose.
  • I like adding the Google Analytics code to WordPress Head because it provides more accurate analytics. While some blogger add the code at the end of the body tag. Read this article for details.

I this article helped you don’t forget to share with your friends. Your every tweet, fb like or +1 will help this site grow. So, help us if you liked. If you have any problem or suggestion leave a comment below.

How to Create Google Chrome App in Less Than 5 Minutes

With Google Chrome, a lot of things are very easy to do. One of them is creating your own app. Yes, we can create an app in less than 5 minutes. (Considering an image icon of 128×128 px is ready to use).

Prerequisites:

  • A credit card for $5 setup fee (Google will charge it for first time).
  • Google Chrome.
  • Your site or blog is added and verified to Google Webmaster Tools
  • App icon with 128x128px in dimension.
  • Screenshot of your site in 1280x800px or 640x400px
  • App image of 440x280px
  • Google Analytics ID (UA-XXXXXX-YY) (Optional)

Google Chrome App Creation:

Create a manifest.json file

Open a text editor (like Windows Notepad) and write the following code and make necessary changes:

{
	 "name": "NetRival - Technology Blog",
	 "short_name": "NetRival",
	 "description": "NetRival is a Blog Focused on Personal Technology, How-to Tutorials, Gadgets and Telecom",
	 "version": "0.1",
	 "manifest_version": 2,
	 "icons": {
		 "128": "icon_128.png"
		 },
		 "app": {
		 "urls": [
			 "http://www.netrival.com/#utm_source=google_chrome&utm_medium=chrome_app&utm_campaign=google_chrome_app"
			 ],
		 "launch": {
			 "web_url": "http://www.netrival.com/#utm_source=google_chrome&utm_medium=chrome_app&utm_campaign=google_chrome_app"
			 }
		 }
 }

Change name, short_name (upto 12 characters), add some description and the urls. Now rename your image as icon_128.png. Create a new directory and place both manifest.json and the icon in it. Now using any compression tool zip the directory.  (We will need this zipped this file later)

Load the created app in Google Chrome:

Open chrome browser and visit chrome://extensions/ then make sure the checkbox named “Developer mode” is checked. You will find it on the top-right of the page (as shown in the image below).

Now “Load unpacked extension” by browsing the directory. Note: Here we don’t have to load a file. Just browsing the directory where the icon and the manifest.json file stored. Google Chrome will automatically load the manifest.json file from that directory. as shown below. In my case the directory was E:\NetRival_Chrome_App (See the highlighted area of the screenshot)

temp-chrome-app

Verify the newly created Chrome Extension:

The plugin should now work. To verify it visit chrome://apps/ (See the screenshot below. If you will click on it. It will open your site or blog.)

verify-check-app

Submit Google Chrome Extension to Official directory.

We will now submit the app to Google Chrome Store so anybody in the world can download it. We have to upload the manifest.json and png in a zipped file (as we have compressed earlier). But first of all we have to pay $5 registration charge to access Google Chrome Developer console. (This $5 charge will allow you submit up to 20 chrome apps and extensions, excluding themes)

Visit https://chrome.google.com/webstore/developer/dashboard and pay the $5 fee. After successful payment hit “Add New Item” and upload the zipped file.

After uploading we have fill some details and add screenshots. You may take the following image as example. Here the screenshots and other images must be in the size mentioned.

chrome-dev-dashboard

 

You may use Google Analytics to track traffic to the Chrome App in the store. Just fill the id and its done for preview. Here, It is recommended to use different GA id than your blog. Now hit “Preview” button at the bottom-right and test-drive how your app looks in Google Chrome Store. Once you are satisfied hit publish button, and you are done.

These demo link and readymade zipped file link will help you. Go ahead and create a Google Chrome app in just minutes. Good Luck!

Demo: https://bitly.com/NetRivalChromeApp
Demo Files: Download Here