Sunday, March 27, 2016

Setting Analytics Account

To set a universal analytics account with Google, you first need to have a Google account.
You can setup a new Google account or use the existing one for this cause.

To set an Analytics account…use this link: http://google.com/analytics

After login into your Google account, you will be redirected to the Google analytics sign up page, which will look like –



On clicking the sign up button, you will be taken to a form where it’s needed to fill the required details. If the form submission goes fine, your account is successfully created!!


Now, you may have multiple accounts related to multiple sites within same Google analytics account.
On clicking Admin, written at the top of any page of your Google analytics page, you can see that Account – Property – View dropdowns. A snapshot is attached here to give you the idea of the same.

Before getting started with analytics, you must understand the followings –


Account – Account is your Google analytics account which is required to access properties and views. An account may have more than one property, containing the views in them.

Property – A Property is a website or mobile application. A property may contain many views of its own.

View – A view is created to keep customized reports in a manageable way. When a property is created, the associated view with no customization is created itself. This view should NOT be deleted as if your custom view has wrong settings and you delete it, all the data is also deleted which cannot be recovered. So it’s good to keep a copy of your analytics data.

User – Multiple users can be added to an analytics account at view and property levels, with different permissions, as required.

The custom reports created may take some time to show data as the analytics do not have data for these reports, but other reports which are present already renders data immediately.

Now on selecting the view from the home, the default dashboard is loaded which contains graphical representation of site analysis data, you can select various dimension-metric combinations to view details. Also, two metrics can be compared.

Initially, the data is too less but after some time as the analytics details are populated, the dashboard will look like this –


The data can be compared on timeline by selecting two metrics. You can also select the data range for more specific data – 

 

Dimensions and Metrics –

Every report in Analytics is made up of dimensions and metrics.

Dimension describes characteristics of your users, their session and actions. Some Examples are – Country or city name from which user accessed from website.

Metrics, on the other side, are the quantitative measurements of your website analysis. Pages accessed, number of sessions, duration on a page…all are examples of metrics.

All the metrics cannot be combined with all dimensions. The combinations depend on the scope of dimension and metrics. Scopes are – Users, sessions and actions, and it would not be logical to combine a session level dimension with an action level metrics.


The data which can be tracked using analytics account are listed in pictures.

These are the parameters for which, the data is analyzed and stored of later usage.

In order to get the data which is not provided by analytics reports, we can make our own custom variables and use them as dimensions. By doing this, the data for metrics can be obtained for this particular variable and viewed thereafter.

We can make custom dashboards, widgets and variables for our ease on the basis of requirements.


Custom Dashboard

            By default, analyst account have a default dashboard for each view which can be found under Reporting > Dashboards > Private > My Dashboard. This dashboard contains some data to demonstrate some analytics statistics.

These data sections are widgets which can be edited, removed or added to the dashboard.
Many default widgets are provided in analyst account which can show data in the form of tables, timelines, pie charts, counters, bar charts, metrics and geo-maps.

But, the dashboard can be organized in the way it suit you. Simply, remove the widget sections which you do not need. You can only create your own dashboard by clicking on Reporting > Dashboards > + New Dashboard. If you want some data by default, choose Starter Dashboard. Otherwise, choose Blank Canvas for a completely empty dashboard and manage it afterwards by adding widgets to it.
If you want different metrics in the same widget. Click on the  button (which appearswhen you hover on an existing widget box). Now change the values accordingly in the pop-up and save it to apply changes.

New widgets, with data of your choice, can be added by clicking on the “Add Widget” button –

 As clear from the picture, the data from the dashboard can be shared, e-mailed or exported. Along with this, you can also delete the dashboard, but only when you really don’t need it (Remember, the custom data cannot be restored once deleted, so beware.)


Custom Widgets

Widgets are the representational structure for your data for making it easy to understand. A Widget may demonstrate data in the form of tables, timelines, pie charts, counters, bar charts, metrics and geo-maps.

You can add widgets to any dashboard which may be a default, custom starter or custom blank dashboard…whichever suits you.
Firstly, click on “Add Widget” button which is located just below the name of your dashboard.


Now, a pop-up window will appear on the screen, which looks like this –


Fill the title of widget which is the name of your widget. Choose it wisely to prevent yourself from getting confused. Give it a name according to the data which it will contain.

Then select the method of representation from multiple available ways. For example, if You select a Table Representation, the data will appear in tabular format.

Finally add the metrics and filters according to your needs and you are all set. Click on Save button.

If you want to add a widget for some data, which is not automatic, you need to add Custom Variables first, which is described in next section. After which that variable can be selected to create a widget carrying data you wanted. Keep in mind, the widget created using this method is blank initially and populated later (If all goes well) as the data is not calculated from beginning itself.

For example, you may want to see IP Address, Number of hits and average time, spend by people from specific IP Address. It is possible to add such widget by using custom variables and appropriate metrics and filters.

Custom Variables

For adding custom variables you have to go to Admin Tab.
Now check the options listed for your property which are just listed below your property Dropdown.

Select the property, to which, you want to add Custom Dimension or Custom Metrics.
Click on the Custom Dimensions or Custom Metrics under the Custom Definitions Section of the property, to which you want to add your variable.
I am going to demonstrate adding Custom Dimension to your property as both processes have same flow.

Always remember, you can add only 20 custom dimensions and 20 custom metrics and these CANNOT be deleted. So, when you need a custom dimension or property…just edit the old unused one, which you do not need now!!


Now, you can add a DIMENSION by clicking on + NEW CUSTOM DIMENSION button. A form will be displayed on the screen, which will resemble to this one –


I am Adding a Field to Get the IP Address of the users who visit my website.

By clicking on create, your variable is added to the list.

Click on the custom variable which you have just created, you will get the code snippets for multiple platforms. Use can add JavaScript, Android and iOS SDKs, as captured in this image –


As I am going to add IP Address tracker to the analytics, it’s required to calculate the value of the USER IP before adding the code snippet to our website pages.

Code to Calculate IP Address of the visitors –

As this code is putted in the <head> section, anywhere before closing of the HEAD tag, you are advised to calculate the value to be sent before head.

<?php
 if
(!empty($_SERVER['HTTP_CLIENT_IP'])) {
 $ip=$_SERVER['HTTP_CLIENT_IP'];}
 Else if
(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];} else {
 $ip=$_SERVER['REMOTE_ADDR'];}
?>

The variable $ip contains the value which you want to send through the analytics code. So, get this value in a JavaScript variable by doing the following –

<script
type="text/javascript">
var dimensionValue = '<?=$ip;?>';
</script>

It’s better to keep this code in the head section.
Finally, the code which will send value to your Google analytics account is –


ga('set', 'dimension3', dimensionValue);

here, it’s necessary to copy this code from the code snippet provided in your account, as you cannot predict the name which is assigned to your custom value. (In this case, it is dimension3 as I have two old properties already). dimensionValue is the name of JavaScript variable you have created, which may differ accordingly.

Finally, here, the whole code is summarized to give you a clear understanding of the usage.

<head>
...
// rest of code…
...
<script type="text/javascript">
var dimensionValue = '<?=$ip;?>';
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
 ga('send', 'pageview');
ga('set', 'dimension3', dimensionValue);
</script>
...
// rest of code…
...
</head>