Not logged in. · Lost password · Register
Forum: Customising UNB Modifications and plug-ins RSS
Need help finishing up a Google Analytics plugin
IANAP!  (I am not a programmer)
Avatar
halr9000 #1
User title: Psi Webmaster
Member since Jul 2004 · 157 posts · Location: Atlanta, Georgia, USA
Group memberships: Members
Show profile · Link to this post
Subject: Need help finishing up a Google Analytics plugin
Ok, I read in the docs some of the plugin hooks, then hacked the custompage.php plugin to come up with something I think is 95% done.  It doesn't actually do anything right now though.  :)  Here's what I have, maybe you can help me make it work.  Messy code follows:
  1. <?php
  2. /*
  3. Name:   Google Analytics UNB Plugin
  4. Purpose:    This plugin allows you to easily insert Google Analytics javascript code into your UNB forum.
  5.         See http://www.google.com/analytics for more details on why you would want to do this.
  6. Version:    0.1
  7. Author: Hal Rottenberg <hal@halr9000.com>   
  8. */
  9. if (!defined('UNB_RUNNING')) die('Not a UNB environment in ' . basename(__FILE__));
  10.  
  11. // Define plug-in meta-data
  12. UnbPluginMeta('Google Analytics');
  13. UnbPluginMeta('Hal Rottenberg <hal@halr9000.com>', 'author');
  14. UnbPluginMeta('en', 'lang');
  15. UnbPluginMeta('unb.stable.1.6.rc.3 unb.stable.1.6.99', 'version');
  16. UnbPluginMeta('unb.devel.20051014', 'version');
  17.  
  18. if (!UnbPluginEnabled()) return;
  19.  
  20. function UnbHookInsertGA()
  21. {
  22.  $ua = "foo"; // Insert yours here.  Someone please code a form for me?
  23.  $GAscript = "<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script><script type=\"text/javascript\">_uacct = \"$ua\";urchinTracker();</script>";
  24.  return $GAscript;
  25. }
  26.  
  27. // Register hook functions
  28. UnbRegisterHook('page.htmlhead', 'UnbHookInsertGA');
  29.  
  30. ?>
-hal
http://psi.affinix.com
http://halr9000.com
Avatar
Yves (Administrator) #2
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Check out the plug-in documentation. It has a list of all hooks with the data passed to the handler function. You need to access this data because you must pass your changes back in them. The return value must be true, if it's false, the hook chain will stop after this function. If it's not boolean, behaviour is undefined. So your code looks like follows:

  1. //...
  2. function UnbHookInsertGA($str)
  3. {
  4.  $ua = "foo"; // Insert yours here.  Someone please code a form for me?
  5.  $GAscript = "<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script><script type=\"text/javascript\">_uacct = \"$ua\";urchinTracker();</script>";
  6.  $str = $GAscript;
  7.  return true;
  8. }
  9. //...
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
halr9000 #3
User title: Psi Webmaster
Member since Jul 2004 · 157 posts · Location: Atlanta, Georgia, USA
Group memberships: Members
Show profile · Link to this post
That didn't seem to make any difference.  Hmm.  No errors, but no script in <head> either.
-hal
http://psi.affinix.com
http://halr9000.com
This post was edited on 2005-11-16, 19:56 by halr9000.
Avatar
Yves (Administrator) #4
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Ok, my fault.
  1. function UnbHookInsertGA(&$str)
see the "&" there
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
halr9000 #5
User title: Psi Webmaster
Member since Jul 2004 · 157 posts · Location: Atlanta, Georgia, USA
Group memberships: Members
Show profile · Link to this post
Cool, it worked.  :)
-hal
http://psi.affinix.com
http://halr9000.com
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 224.8 ms (118.6 ms) · 62 database queries in 136.2 ms
Current time: 2012-02-07, 19:38:17 (UTC +01:00)