1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Google Analytics 0.5

Add Google Analytics tracking code to Hotaru

  1. carlo75

    carlo75 Design & Development

    Google Analytics
    Version: 0.5
    Author: Carlo Armanni
    Created on: 2009/11/24
    Last Updated: 2011/03/29
    Tested on: Hotaru 1.0.5 ~ 1.4.2
    Plugins Required: None
    Plug & Play: Yes
    Supported: Yes

    Description
    This plugin allow you to add Google Analytics tracking code to Hotaru, in a simple way. This plugin doesn't count the visits made by user with Admin right (admin permissions)

    Instructions
    1. Upload the "google_analytics" folder to your plugins folder. Install it from Plugin Management in Admin.
    2. Access it from the Admin sidebar
    3. Enter your Web property ID provided from Google Ananlytics and save.

    Revision History
    v.0.5 2011/03/29 - Carlo - Updated GA code and added control for Admin permission
    v.0.4 2010/08/30 - Carlo - Updated hook, to correct snippet in insert <head> tag
    v.0.3 2010/08/27 - Carlo - Updated for new GA Snippet Code
    v.0.2 2009/12/18 - Nick - Updated for Hotaru 1.0
    v.0.1 2009/11/24 - Carlo - Released first version

    Please click "Rate Thread" and give this plugin a rating. Thank you.
     

    Attached Files:

    Last edited: Mar 29, 2011
  2. Nick

    Nick Well-Known Member

    Excellent work Carlo. A great choice for your first plugin! :)
     
  3. angolanmade

    angolanmade Well-Known Member

    Awesome stuff. How much different/difficult would be to change this plugin to work with Piwik, open source web analytics software that aims to be an alternative to Google analytics.
     
  4. carlo75

    carlo75 Design & Development

    @Nick
    Thank you so much... you are the grand master ;)

    @angolanmade
    I don't know how Piwik works, but if it's use tracking code like Google Analytics, I think there are no big problems... please let me know.
     
  5. angolanmade

    angolanmade Well-Known Member

  6. Nick

    Nick Well-Known Member

    Code:
    <!-- Piwik -->
    <script type="text/javascript">
    var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$PIWIK_URL}" : "http://{$PIWIK_URL}");
    document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
    </script><script type="text/javascript">
    try {
    var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$IDSITE});
    piwikTracker.trackPageView();
    piwikTracker.enableLinkTracking();
    } catch( err ) {}
    </script>
    <!-- End Piwik Tag -->
    http://piwik.org/docs/javascript-tracking/
     
  7. carlo75

    carlo75 Design & Development

    Need to manage $IDSITE
    no problem on that, when for $PIWIK_URL can be retrieved from global of Hotaru BASEURL while for https need a little string manipulation
     
  8. Gunaxin

    Gunaxin Well-Known Member

    I know this was a relatively simple plugin, but I was wondering if you might be interested in updating with new functionality. Specifically I'd suggest Event Tracking for outgoing clicks. Its great to measure traffic on your site with Google Analytics, but tracking how much outgoing traffic you are sending to other websites is crucial as well.

    See this link from Google on a method to do this :

    http://www.google.com/support/googl...wer=55527&cbid=-777fkgbyax26&src=cb&lev=index

    In their example they track to www.example.com, which would obviously need to be some php to pull the proper domain name. Having this tracked / summarized by domain would be more beneficial than just by link, but I'm not sure if their is currently a field / variable for that.

    Any chance I could encourage you to give this a shot? The toughest part is putting the onclick on all of the outgoing links. I'm not sure how you would do that without manually modifying all plugins which have them.
     
  9. carlo75

    carlo75 Design & Development

    Hi Gunaxin,
    thank you for your suggest, I'll try to play with the plugin, and add this new function... althought atm I prefer increase new themes for HotaruCMS
     
  10. Gunaxin

    Gunaxin Well-Known Member

    In order for this option to work properly, its best to send Google Analytics just the domain that the traffic is going to, not the entire URL. I'm not sure if there is currently a field for this, but I'd love to actually be able to display that on my page as well. Maybe Nick knows?

    I'd probably be willing to sponsor development of this tracking functionality, as its fairly important to me. Let me know if someone is interested in undertaking it. Thanks.
     
  11. Nick

    Nick Well-Known Member

    If you mean the domain of the original post, yeah it's in the post_domain column in the posts table and accessible using $h->post->domain.
     
    Gunaxin likes this.
  12. Gunaxin

    Gunaxin Well-Known Member

    Sweet. Thanks!

    Just added the domain here : http://links.gunaxin.com/

    Used : <?php echo substr($h->post->domain, 7);?> since it contained http://

    I could also make it link using that same field, which I may add later. Also with that information, I'll take another stab at this analytics thing, although I'll be doing it a brute force way.
     
  13. mabujo

    mabujo Designer

    I just wrote you this bit of jquery to add the add the onclick on the outgoing links.
    If you wrap this inside a .php file you can get the $h->post->domain and put it where 'example.com' is below :

    Code:
    $(document).ready(function(){
    	var goog_onclick = "recordOutboundLink(this, 'Outbound Links', 'example.com');return false;";
            $(".click_to_source").attr('OnClick', goog_onclick);
    });
    
     
    Gunaxin likes this.
  14. Gunaxin

    Gunaxin Well-Known Member

    Very cool, thanks for the help. It seems like I have all of the pieces I need, so I am trying to get this sorted out. This is where my lack of knowledge really kills me, because I can only get so far with guessing. =)
     
  15. Gunaxin

    Gunaxin Well-Known Member

    Ok, so the Event tracking (despite help above) kicked my ass for awhile. I just couldn't get it to work. So I realized I should just look at my Wordpress site and figure out how it was done there. There I have a far simpler solution :

    I just added this to each of my outgoing links (sb_list, sb_post, and display_image for me)

    Code:
    onclick="javascript:pageTracker._trackPageview('/outbound/<?php echo substr($h->post->domain, 7);?>');"
    The drawback with this method is that it technically counts outbound clicks as pageviews, so it will distort your numbers some. However you could always subtract that out, or if you're like me, the outbound clicks are more important than the pageviews. I am sure there is some better way to add this snippet to each outgoing link, but I just shoved it in those templates (which I have already customized anyways)
     
    Nick likes this.
  16. samuliakin

    samuliakin New Member

    Problems with Analytics plugin

    I've installed the plugin and inserted the web property id but it does not appear to be displaying any results in my analytics account. I did not take the snippet of code from analytics and put it on all the pages i wanted to track. Was that step necessary? Or is there something else I should do?

    Thanks
     
  17. Nick

    Nick Well-Known Member

    @samuliakin What's your url, so we can take a look?
     
  18. samuliakin

    samuliakin New Member

    nvm, it looks like its working
     
  19. narc

    narc Well-Known Member

    Nice Plugin, need this for Piwik to ;) -
     
  20. richrf

    richrf New Member

    Hi,

    Thanks for the plugin! It seems like the code being generated is the old google analytics tracking code and not the new asynchronous code. Is this correct? If it is the old code, where would I place the new snippet? In the footer of the theme? Thanks.

    Rich
     

Share This Page