023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Google's Highly Open Participation Program tries to get young students into Open Source and Joomla! specifically. Everyone is welcome, there are not limits. You can be a coder, documenter, tester, translator to help out. Jump in and start helping!
kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Thu Nov 29, 2007 7:52 pm

Hi all

I'm in my second last year of high school in South Africa, my hobby has been php development on top of the Java work we do at school.

Description of task: (http://code.google.com/p/google-highly-open-participation-joomla/issues/detail?id=23&colspec=ID%20Status%20Summary)
Create a module to embed Google Analytics into Joomla! v 1.5.
Describe the task.

Create a module to embed Google Analytics tracking code into a template.
Create an installable zip file for the module.


I think I have everything done alright (unless there was something else completely in mind...) - so basically right now I'm just looking for comments/criticism :D - I've attached what I have so far.

Thanks  8)

Google Task

[me=AmyStephen]Changed subject slightly for sorting all threads to match against Google resource  :)[/me]
You do not have the required permissions to view the files attached to this post.
Last edited by AmyStephen on Mon Dec 17, 2007 5:17 am, edited 1 time in total.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 23 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Thu Nov 29, 2007 8:00 pm

Welcome to Joomla! and thanks for participating in the GHOP Contest!

I am certain your work will prove very valuable to the community. Ercan Özkaya (aka Pentacle) has agreed to be your task sponsor. When he has a moment, he will stop by, introduce himself and review your work, providing you with feedback.

Good luck with the contest and do not hesitate to ask for help, if needed.
Amy :)

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: 23 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby Pentacle » Thu Nov 29, 2007 9:25 pm

Hi,

As Amy told, I'll be helping you during your task. I appreciate your contribution to the Joomla! and open source world very much. This is how open source survives: with the help of volunteers contributing generously.

First of all, I will mention about the new and more object-oriented (thus, more convenient) way for developing modules in Joomla! 1.5. You can see how it works in most of the core plugins or in the module tutorial in Developer's Wiki.

I would rather use this way as it's easier to maintain the code and add new functionalities. And as we are a big and international community, your module should use language files in order to be translatable. So people can use it in their own languages if they want. You can take look at my plugin called Title Manager about how you can implement multi-language behavior.

If we turn back to the code, first thing I would like to say is your way of getting _uacct code may cause problems. For example if there is white space before the '_' character, you can't get the needed data. So I would prefer using _uacct code as a parameter instead of splitting it from the whole code block. This would also be quicker.

Secondly, Google Analytics has SSL support and the script url is different for this option. You can determine the SSL need with a parameter in backend and then use the global variable of PHP -$_SERVER['HTTPS']- to feed the correct URL.

And there are some missing fields in your XML file like copyright and licence. You should fill them.

If there's anything I can help, don't hesitate to ask here and please let me know when you have a new release.

Thank you very much for your efforts. :)

Ercan.
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 23 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Thu Nov 29, 2007 9:35 pm

Ok Cool - I'll make the changes over the next few days...

Just to explain my rational with the _uacct code - because of the way in which Google presents the Analytics code (making it harder to select a single part) I thought that this would be 'simpler' from a basic user's point of view - but I'll change it to a simple parameter unless I think of something better than that.

Thanks

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: 23 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby Pentacle » Fri Nov 30, 2007 9:21 pm

kilps wrote:Just to explain my rational with the _uacct code - because of the way in which Google presents the Analytics code (making it harder to select a single part) I thought that this would be 'simpler' from a basic user's point of view - but I'll change it to a simple parameter unless I think of something better than that.

Thanks


Your idea is very good indeed, but I think sometimes we should trust the data user supplies to make things faster and easier. And this code is easy to find after including some hints in documentation.

And one more recommendation. You shouldn't use the deprecated way of getting site title.

Good luck to you.

Ercan.
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Sat Dec 01, 2007 8:19 pm

Hi there

I think I've fixed pretty much everything (I just need to update documentation still) - but I'm just having a problem with getting the page title.

I am using JDocument::getTitle() to fetch the page title - but it isn't returning anything... I can't seem to figure out how else I should be displaying the title :(

I've attached everything so far.

Thanks
You do not have the required permissions to view the files attached to this post.

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby Pentacle » Sat Dec 01, 2007 8:33 pm

Hi again,

Well your problem about title is calling object method statically. You should first get a reference to JDocument object and then call the method like $document->getTitle().

After looking at your code again, the progress is amazing. Three more little advice:
* You can use ternary operator of PHP instead of some if-elses.
* Moving the HTML code to the template file will make it easier to work on, I think.
* In your module backend, using the 'Yes' options first would be better in my opinion.

I'm looking forward to future versions of your module. Keep up the good work!

Ercan.
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Sun Dec 02, 2007 3:40 am


kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Sun Dec 02, 2007 8:27 pm

Pentacle wrote:Well your problem about title is calling object method statically. You should first get a reference to JDocument object and then call the method like $document->getTitle().

Ok cool figured that out - thanks :)
Pentacle wrote:* You can use ternary operator of PHP instead of some if-elses.

That's done.. Much simpler than what I had before  :D
Pentacle wrote:* Moving the HTML code to the template file will make it easier to work on, I think.

I'm curious as to why you think so/how you would do - my understanding is that the helper.php is meant to do all the calculation type work and then the template file the formatting - but I can't help but feel that separating the two tasks is just going to result in lots of little functions which are going to confuse things and are unnecessary considering the simple logical formatting of what we want to output - that is unless I missed something ..  :-\
Pentacle wrote:* In your module backend, using the 'Yes' options first would be better in my opinion.

Ok I've done this for the title parameter - I just think that the SSL option should stay at No considering that this is what most users will be using and those who need SSL will select it.

I've attached what I've changed, I'm working on updating the documentation right now - and thanks, I learnt some new stuff today  8)
You do not have the required permissions to view the files attached to this post.

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby Pentacle » Sun Dec 02, 2007 8:46 pm

kilps wrote:I'm curious as to why you think so/how you would do - my understanding is that the helper.php is meant to do all the calculation type work and then the template file the formatting - but I can't help but feel that separating the two tasks is just going to result in lots of little functions which are going to confuse things and are unnecessary considering the simple logical formatting of what we want to output - that is unless I missed something ..  :-\


My intention was that if someone wants to change or add a few lines in Analytics code (which is not standart), they would not have to hack the module code, but instead just do a template override. (In case you don't know, Joomla! 1.5 has a great template override system. You can take a look at Beez template to see it in action.) I'm not sure but Google Analytics has some extra things for the code, I think.

Ok I've done this for the title parameter - I just think that the SSL option should stay at No considering that this is what most users will be using and those who need SSL will select it.


I think you misunderstood me. I agree about your thinking of SSL parameter. You can make the SSL parameter 'No' by default even it's the second option.

And about ternary, what about grouping the same parts like this?:

Code: Select all

'<script src=' . ($isittrue ? 'differences' : 'here') . '/blabla.js'


I've attached what I've changed, I'm working on updating the documentation right now - and thanks, I learnt some new stuff today  Cool


I'm getting excited about the release and you're learning about Joomla soo fast. Thanks for your work. :)
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Sun Dec 02, 2007 9:29 pm

Ok well I needa get some sleep  :-\ - I've attached what I've got, will finish the little things (including that documentation...) tomorrow :)

Thanks  8)
You do not have the required permissions to view the files attached to this post.

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 03, 2007 3:43 pm

Ok I think that I may be complete  :D - if I'm right I must post it here before on the Google Code site right? Please let me know if I've missed anything..

Thanks  8)
You do not have the required permissions to view the files attached to this post.

User avatar
Pentacle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 165
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby Pentacle » Mon Dec 03, 2007 5:21 pm

Last things:

* Why do you use textarea-list-list for parameters instead of text-radio-radio? People are used to the second configuration more as most of the core modules prefer this way. (I should have said this before, blame my memory. :))
* You don't have to echo PHP code in template file. Just use HTML code for the constant parts.
* I'd use a $title variable and make it page title if track by url option is on, a blank string if this option is off. This way you won't have to use logic in your template.
* Consider putting an example uacct code in your documentation like UA-123456-01. Who knows, maybe someone will need it. :)

It's the last steps before completing task, I believe. Way to go Geoffrey. :)
My Joomla! 1.5 extensions - http://ercan.us
Progress is made by lazy men looking for easier ways to do things.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Tue Dec 04, 2007 5:52 am

Kilps -

When I first tried to install this, I got the following error message:
Error! Could not find an XML setup file in the package.


Then, I realized I had to unzip the zip file to find the zip file. I wonder what the best way is to include the help files and the install module.

Good job on the language files.

Listen to Ercan's advice - I learn from him all the time! And, when you are ready for a final review, let us know!

Thanks for your contributions to our community. This is another good module that will be used!
Amy :)

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Sun Dec 09, 2007 8:12 pm

Hi

Sorry for the late reply - I've been away this week without internet  :-\

I've made all the said changes and have attached  :) - should I be uploading this to the Google Code Issue aswell?

Thanks
You do not have the required permissions to view the files attached to this post.

annerajb
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Tue Sep 04, 2007 8:59 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby annerajb » Mon Dec 10, 2007 4:09 am

quick question woundt this be better using jdocument add script. also i was coding my own plugin for jurchin some minutes ago and i just noticed this :P isnt this better as a plugin so every page is tracked instead of just the ones that you put the module on?

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 10, 2007 10:07 am

annerajb wrote:quick question woundt this be better using jdocument add script. also i was coding my own plugin for jurchin some minutes ago and i just noticed this :P isnt this better as a plugin so every page is tracked instead of just the ones that you put the module on?


It is an idea except that the addscript function adds the script to the head of the page (as far as i can see) - and Google Analytics is meant to be put at the bottom of the page just above the tag (so that the rest of the page loads before the analytics code - speeding things up for the user).

Besides this using the module method allows the user (at least to a point) to decide which pages he/she wants to track.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Mon Dec 10, 2007 1:19 pm

Kilps -

Is this a module that has been upgraded from v 1.0.x? And, if so, which extension did it come from? I ask because of the template name which is a v 1.0.x name. Also, it is important to carry forward copyright information and credit the author.
This module allows you to insert Google Analytics tracking code into your Joomla as a module. It's important that you put this module immediately before the closing body tag, as Google suggests, to the footer section of your site template. E.g in rhuk_solarflare_ii template, you should use the debug position. Set the module title to no and other settings according to your needs.


Why a textarea for the Analytics code?

What does replace URLs with page titles do? (What is the value / purpose of this option?)

Agree - this does not belong in the head section where most scripts reside.

Thanks!
Amy :)

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 10, 2007 1:31 pm

AmyStephen wrote:Is this a module that has been upgraded from v 1.0.x? And, if so, which extension did it come from? I ask because of the template name which is a v 1.0.x name. Also, it is important to carry forward copyright information and credit the author.
This module allows you to insert Google Analytics tracking code into your Joomla as a module. It's important that you put this module immediately before the closing body tag, as Google suggests, to the footer section of your site template. E.g in rhuk_solarflare_ii template, you should use the debug position. Set the module title to no and other settings according to your needs.


I'm a bit confused as to what you mean here. I wrote the module from scratch myself - have I named something incorrectly?

AmyStephen wrote:Why a textarea for the Analytics code?

Woops - forgot to change that, done.

AmyStephen wrote:What does replace URLs with page titles do? (What is the value / purpose of this option?)

It sends the title of the page to Google Analytics instead of the url of it - so when looking at your statistics you see page titles instead of urls (see the documentation for further explanation).
You do not have the required permissions to view the files attached to this post.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Mon Dec 10, 2007 1:33 pm

My question was why "rhuk_solarflare_ii" in the description?

With GPL'd code, it's fine to reuse - part of the beauty. Just important to credit the author.

Thanks!
Amy :)

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 10, 2007 1:36 pm

AmyStephen wrote:My question was why "rhuk_solarflare_ii" in the description?

With GPL'd code, it's fine to reuse - part of the beauty. Just important to credit the author.

Thanks!
Amy :)

Sorry which description are you seeing it in? Not the language files right? I cant see where you see it  :-\

Thanks

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Mon Dec 10, 2007 1:44 pm

I see what I did.  :-[

I downloaded your zip file - and then installed a zip file named mod_analytics.zip already on my desktop from Nick Dawson from v 1.0.x.

Set the module title to no and other settings according to your needs.
  ]]>


This was not yours - you do not have this description in your files.

Your file is named mod_googlanalytics.zip.

It's description is:
A simple module to insert Google Analytics code into a Joomla! installation


My sincere apologies for the mistake. Now, I'll look at YOUR extension.
Amy :)

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 10, 2007 1:47 pm

no problem :)

annerajb
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Tue Sep 04, 2007 8:59 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby annerajb » Mon Dec 10, 2007 2:45 pm

thanks amy thats why my site is slow :S

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Thu Dec 13, 2007 1:23 pm

Hi

I'm not too sure what I should be doing now so I've attached the completed task to the Google Code page...

Thanks

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Thu Dec 13, 2007 3:02 pm

Community Review PLEASE!  8)

Download and install kilps Google Analytics extension and let's try to get this closed today.

Thanks!
Amy :)

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Mon Dec 17, 2007 5:17 am

kilps -

Thanks for this excellent work. It works perfectly and will be helpful to those trying to track website activity.

The task is now closed on Google and you are free to choose another task, if you desire.

Amy :)

kilps
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Nov 29, 2007 7:41 pm

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby kilps » Mon Dec 17, 2007 4:36 pm

Thanks very much :D

User avatar
mmw09er
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Jan 01, 2008 5:00 pm
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby mmw09er » Wed Jan 02, 2008 3:37 pm

I have found this great module and installed it. Upon install I noticed two characters that were being rendered in the footer of my page (single quote and a semi-colon):

';

Upon inspecting the src code /mod_googleanalytics/tmpl/default.php I found the close of the script tag had the same two characters placed outside the close script tag, which did not make sense to me, as shown here:

';

I have removed the two characters and all seems well now. I'll watch my reports & advise if my edit caused any problems.
Matt

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 023 - Create a module to embed Google Analytics into Joomla! v 1.5.

Postby AmyStephen » Wed Jan 02, 2008 7:04 pm

Thanks so much, Matt!  8)

kilps - if you get a chance, please look at Matt's report and see if it makes sense to include his ideas as a fix to your extension. If you do so, feel free to upload the changes to your Google task, again, and perhaps Matt will be kind enough to test and make certain the fixes worked as planned.

Thanks!
Amy :)


Return to “Google's Highly Open Participation Contest”

Who is online

Users browsing this forum: No registered users and 1 guest