Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding something to HEAD section


I've been trying to add some google analytics to the head section of my forum, but I can't seem to get it in right. I downloaded the add-on for the old google analytics and used somebody elses's modifications to update it, but it still doesn't put the code in the head section. Here's the problem code:


$AddGoogleAnalytics = $Context->ObjectFactory->NewContextObject($Context, "AddGoogleAnalytics");
$Page->AddControl("Page_Render", $AddGoogleAnalytics, $Configuration["CONTROL_POSITION_HEAD"]);


I know that last $page command is what needs to be modified, but I'm scared to mess with it again; I crashed the forum a couple of times when I tried to modify an extension. A correction would be nice, but an explanation would be most highly appreciated.

Comments

  • I think you can do this with nuggets? Or isnt there an actual analytics addon? Tons of people have done it..
  • I don't know what nuggets are, and I know this is one of only two google analytics add-ons for vanilla. At least, that's all I got from searching the add-ons with Google Analytics. I just need to know how to change that code to target the head section, versus the top of the body section, as it is now.
  • do you want to display something with that code? or you just want to add the script to the head? (then: $Head->AddScript($Script); )
  • 'CONTROL_POSITION_HEAD' is misleading. It really refers to the top of the Page control which only renders the body of the page, so it's the "head" of the <body>. Fun!

    What you actually want to do to the Google Analytics extension is remove the entire body of the if() statement and replace it with this:

    $Head->AddScript('http://www.google-analytics.com/urchin.js'); $GoogleAnalytics = ' <script type="text/javascript"> // <![CDATA[ _uacct="'.$Configuration['GoogleAnalyticsAccountNumber'].'"; urchinTracker(); // ]]> </script>'; $Head->AddString($GoogleAnalytics);
  • Thanks for your help, squirrel. Can I use that "AddString" command on any sections of the page, or is it exclusive to the Head section? I'm just curious, I've already got my answer.
  • $Panel also has an AddString() method that optionally takes two extra arguments relating to the position of the string on the panel. Check out library/Framework.Control.Panel.php line 65.
This discussion has been closed.