Tuesday 11 April 2017

Exploring your site usage via Google Analytics

Everyone wants to know how their website is performing, how many visitors they have on their site, etc. Google Analytics is one of the most stable solutions to achieve this. It lets you easily gauge at all stats of your website from the visitor perspective and provides you with useful data that can let you improve your website.

So how to use google analytics :
1.  Sign up for a Google Analytics account by following the link- http://www.google.com/analytics/
2.  On successful sign-up, you will be taken to a page that allows you to create a new account.
3.  You will have to enter some data in the form.
4.  After that you will get a tracking id in the format UA-XXXXXXXX-Y.
5.  Now there is option for js code so you will get js code from there and paste this snippet into your
pages which you want to track. There are many options providing by  google 'https://developers.google.com/analytics/devguides/collection/analyticsjs/'

<!-- 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','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXXX-Y', 'auto');
    ga('send', 'pageview');
  </script>
<!-- End Google Analytics -->

6. For configure this js snippet according your requirement please visit this
  'https://developers.google.com/analytics/devguides/collection/analyticsjs/how-analyticsjs-works'


In above js snippet there is ga() function which is used to send the data to google analytics. ga() function have the many arguments on the basis of that you can track your site as your requirement.
First argument is 'send' which means you have sending something and it is fixed argument.
Second argument may be 'pageview' or 'event' = On the every page there are many blocks and if we want to track each and every block seperataly then we have to use 'event' and if we want to track only page means how much time page is visited and form which pages to visited and how many users visited so we have to use 'pageview' .

Page view:-
In the pageview google track your whole page means how many time this page is visited, form which page you have to redirect to this page and how many users visited this page.There is snippet of js provided by google analytics which is to be placed in that page which you want to track.
This is function for pageview
'ga('send', 'pageview', location.pathname)'.
ga is fucntion which is send the page data to the google analytics.
send and pageview are the fixed parameter but you can change locaio.pathname by page url, page title.
for more detail 'https://developers.google.com/analytics/devguides/collection/analyticsjs/pages'

Event Tracking:-

Now on our site there are many block on a single page and we want to categorized them so we can analysis them in better way, for that we have to categorized them and have to write event tracking code for each and every event.
We want to track an activity on page without reload the page. Downloads, mobile ad clicks, gadgets, Flash elements, AJAX embedded elements, and video plays are all examples of actions you might want to track as Events.
For this you have to use event tracking method
'ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject])'

Send and event are fixed parameter.
We take a condition like there is social share a block which have social share icons like (fb, twitter, linkedin), now,
[eventCategory](REQUIRED) = category name(You have to categorized the events like there is event category name is "SOCIAL SHARES" )
[eventAction](REQUIRED) = "CLICK"
[eventLabel] = "ICON TITLE(LIKE FACEBOOK, TWITTER) OR LINK"
[eventValue] = "ANY NUMERIC VALUE"
[fieldsObject] = In some cases you might want to send an event as a non-interaction event then set the value true.
(https://support.google.com/analytics/answer/1033068#NonInteractionEvents)

For more detail 'https://developers.google.com/analytics/devguides/collection/analyticsjs/events'

Google analytics for Drupal sites.
1. Install the module google_analytics(https://www.drupal.org/project/google_analytics)
2. Configure it and set the tracking id.
3. There are some options available you can configure according your requirement.
4. This module is sufficient for tracking page views.
5. If you want to tracking event theve to  you hacinstall google_analytics_et module (https://www.drupal.org/project/google_analytics_et).
6. Now write a custom module and write a hook 'hook_google_analytics_et_api()'
7. It returns a array which has some keys like
  'event', 'selector' ,'category' 'action', 'label', 'value', 'noninteraction'

  For example:-
  $selectors = array(
    array(
      'event' => 'mousedown',
      'selector' => '.menu-block-wrapper.menu-name-menu-call-to-action li a',
      'category' => 'CTA',
      'action' => 'click',
      'label' => '!href',
      'value' => 0,
      'noninteraction' => TRUE,
    ),
    array(
      'event' => 'mousedown',
      'selector' => '#block-follow-site .follow-links a',
      'category' => 'Social icons',
      'action' => 'click',
      'label' => '!href',
      'value' => 0,
      'noninteraction' => TRUE,
    ),
  )


For label there are some option
!text
 This is what would be returned from the jQuery .text() method.
!href
 The value of the href attribute (handy with anchor tags).
!currentPage
 The URL of the current page (this is taken with the code window.location.href

8. Now GA is ready for your drupal site.

No comments:

Post a Comment

Thanks!