New Google Analytics plugin

I’ve just created my first plugin for zenPhoto. Go to http://www.moto-treks.com/zenPhoto/google-analytics-for-zenphoto.html to download. This plugin started its life as the google maps plugin.

I had been modifying the core code to insert the google analytics js but with the last update to zenPhoto I decided I’d just create a plugin to handle the majority of the work. Now all that’s needed is to add the function call to your template files.

I searched for a while on this site and reviewed the zenPhoto code but I didn’t find a way to write a plugin that would insert html code without needed to modify the template files to include a function supplied by the plugin. I saw the function addPluginScript but this only adds scripts to the header section of a webpage.

Does anyone know if it’s possible to write a plugin that will output html without using a function call within a template?

Enjoy!
Jeff

Comments

  • The `addPluginScript()` function can be used for anything you want to insert. But, of course, it will do the insertion to the header. Anything else requires the user to modify his theme files.
  • Thanks for the confirmation. I had hoped I had just missed something. Maybe enhancing the plugin architecture to accommodate such a feature (html output without functional call) is something that you can keep in the back of your mind.
  • So, how would you propose to do that? Where in the rest of the HTML would it go? And, without a function call, how would it get there? No, I am afraid that magic is not possible. Even the stuff in the header requires a function call, all be it one that is normally present.
  • I’ve not researched the technical details but I do know the capability exists. For example, I’m using Joomla to drive my website and I recently added an extension to allow comments to the articles. I did not need to modify my template’s php code to include a function that would enable comments. They just “magically” appeared on all articles. I know it’s not magic, and for sure the architecture behind Joomla is different than zenPhoto, but my point is, it can be done. With the little I know about the Joomla templates, there may well be a generic core function call that someone creating a template includes. The generic core function may cycle through all enabled extensions invoking them so that the extensions can do their magic. Something like this would enable users, which are not a technical as others, to take advantage of the plugin’s features. I should learn more about this as I want to create an extension in Joomla for zenPhoto.

    I really like zenPhoto and you guys are doing a great job but from what I’ve seen in zenPhoto this type of architecture does not exist. My suggestion to keep it in the back of your mind was because I imagine this is not a simple change to zenPhoto. At a minimum, zenPhoto would need to keep a collection of plugins which extend the HTML. These plugins would need to inherit a class structure to implement a known interface. A new core template function could then invoke each plugin in the collection. Yes, any template wanting to be plugin friendly would need to be modified but that would only need to be done once.

    Anyway, just an idea.
  • j916 Member
    I've updated the Google Analytics plugin (v1.1) to use the latest coding practice suggested by Google. Now, the plugin will handle any errors that may occur during Google page tracking.

    Go to http://www.moto-treks.com/zenPhoto/google-analytics-for-zenphoto.html to download.
  • acrylian Administrator, Developer
    Thanks, I will add it to our plugins page where we actually forgot to add it.
  • Is this still working for anyone in v1.2.9? Just upgraded and doesn't seem to be working. Verified plugin is still there. I also tried to deactivate it and reactive the plugin and nothing. Trying on zenpage theme now and just manually added the google analytics code to the footer.php file and it's working fine for now

    (edit)
    Disregard that. Forgot it doesn't show the code if you're logged in as admin.
  • j916 Member
    Google recently released updated tracking code for Google Analytics which allows for asynchronous tracking. I just updated the google analytics plugin to version 2.0 which takes advantage of the new capabilities.

    The best thing about version 2.0, is that you don't need to modify a template to insert the tracking code. Because the communication with google is done asynchronously, the tracking code can be placed anywhere in your template. Before, it was suggested to be placed near the bottom of your page. With the asynchronous interface, the tracking code should be placed near the beginning of the page. zenPhoto (v 1.3.1) provides an interface that enables plugins to place code in the header section. This upgrade takes advantage of this interface and the google asynchronous capabilities to insert the tracking code in the header section of you page.

    What this all means is you can install this plugin, use any template you want, and always have google analytics tracking your code.

    The upgrade is easy too, just replace the google_analytics.php file in the zp-core/zp-extensions directory and you're done. You don't even need to remove the old code in you're template for the version 1.1 plugin.

    As a side note, I noticed that in a future version of zenPhoto (1.3.2 maybe) a new enhancement to the plugin interface will enable code to be placed at various locations, like at the beginning of the body section. When this enhancement is available, I'll provide an update which takes advantage of these capabilities.

    Oh, plugin can be downloaded at http://www.moto-treks.com/extras/file-download/view.download/6/6

    enjoy,
    Jeff
  • acrylian Administrator, Developer
    Thanks for the update. Very appreciated that you are maintaining this.
  • Just noticed that 1.4.0.1 is out. Great job guys!

    I found myself with a few free hours today so I updated my site as well as worked on this plugin. Now, thanks to the 1.4, the Google Analytics plugin supports the theme filter methodology. Meaning, as long as your theme supports new 1.4 capabilities (I had to modify my theme too) all you need to do is add the Google analytics plugin to you plugin directory.

    I'll test my modifications for a few days an then publish my update.

    Jeff
  • lkjs Member
    This no longer seems to be working. It is error 17. I modified the script but it can't seem to find a pathway.
  • acrylian Administrator, Developer
  • lkjs Member
    I just came back to update that I found that. :-) Thanks.

    Everything working great.
  • acrylian Administrator, Developer
    Great :)
  • j916 Member
    OK, I’ve been a little lazy about getting the update out – my bad. I just uploaded the file to my website. This version has been running for a few months on my website.

    The update takes advantage of the new ‘theme_body_open’ filter in 1.4. What this means is that, as long as your template supports the zp_apply_filter methods, you don’t need to modify you template to use Google Analytics for zenPhoto.

    I’ve also modified it so that you can install the plugin outside of the zp-core directory to ease zenPhoto updates.

    As always if you find a problem leave me a comment on the download page - http://www.moto-treks.com/software/22-google-analytics-for-zenphoto

    enjoy
  • acrylian Administrator, Developer
    Maybe micheall and you could get together so we have only one of these...two seems really too much for it. Also I really don't want to update/change the links all the time...
  • j916 Member
    I just followed the google analytics extensions link above and saw that we now have two - hmmmmm guess I should be more responsive with my updates ;-)
  • No by all means, I only updated/released it at request since I and others had issues on the change over a few versions ago ;)
  • acrylian Administrator, Developer
    Ok, then I will change the link and credit on hte plugin's entry back.
  • j916 Member
    Maybe it's time this becomes an official zenPhoto plugin. It's been available for something like 2 years, as evident, people do use it and I do get wrapped up in other tasks so i'm not aways responsive to needed updates - just say'n
  • acrylian Administrator, Developer
    Well, we really don't make plugins official that easy. We have already enough to maintain with the current plugins and stuff. Actually it is not really hard to add this GA code directly....;-)
  • j916 Member
    Yes, I've seen the posts on the adding of GA code. I guess the difficulty someone may have in adding GA code directly is subjective to how proficient they are at coding. Additionally, if one uses a default templates then the GA code needs to be added ever time there is an update - one of the reasons I created the plugin in the first place.

    Anyway, it was just a suggestion - didn't want you to have to chance links every time I'm a little lazy ;-)
  • acrylian Administrator, Developer
    I just add links to both of you.,,(sorry, micheall..;-))
  • Version 2.5 is now available. This update of Google Analytics for zenPhoto inserts the tracking code in the page header and body for faster page loading

    http://www.moto-treks.com/software/22-google-analytics-for-zenphoto
  • acrylian Administrator, Developer
    Great. j916, is there anything by micheall in there? I just updated the extensions entry with your link (had still the link to micheall's site) and you two are listed as authors. We just want to be correct on this. Please check the entry http://www.zenphoto.org/news/google-analytics and let us know.
  • Shouldn't be as I never downloaded micheall's version.
Sign In or Register to comment.