Simple Machines Community Forum

SMF Support => SMF 1.1.x Support => Topic started by: mvc on January 20, 2008, 01:33:42 AM

Title: Google Analytics changes formatting - why?
Post by: mvc on January 20, 2008, 01:33:42 AM
HI, I pasted the google analytics code in the index.template.php which I beleive is the right spot.  It is at the end of the code.  When Iput it in, it changes the entire formatting of SMF. 

a couple questions

1.  Is this the right spot?
2.  Why the change in formatting and how do I get it to not change the format?
Title: Re: Google Analytics changes formatting - why?
Post by: IchBin™ on January 20, 2008, 02:58:14 AM
Hard to tell anything when we can't see what you have done. Can you post a link, or show us your code? If you show us the code, please include a good chunk of code above and below your google code. Thanks.
Title: Re: Google Analytics changes formatting - why?
Post by: mvc on January 20, 2008, 09:53:56 AM
Here is the end of code for index.template.php with the added google analytics code.  I didnt alter any code other than to paste it in.  When I take the code out, the formatting is fine.  When I put it back,the formatting changes to increase the font size of everything.  wierd.

I am wondering where other folks have put this code and if they have he same issues.  I saw a few postings but no real answer.  Thanks all!



// Generate a strip of buttons.
function template_button_strip($button_strip, $direction = 'top', $force_reset = false, $custom_td = '')
{
   global $settings, $buttons, $context, $txt, $scripturl;

   // Create the buttons...
   foreach ($button_strip as $key => $value)
   {
      if (isset($value['test']) && empty($context[$value['test']]))
      {
         unset($button_strip[$key]);
         continue;
      }
      elseif (!isset($buttons[$key]) || $force_reset)
         $buttons[$key] = '<a href="' . $value['url'] . '" ' .( isset($value['custom']) ? $value['custom'] : '') . '>' . $txt[$value['text']] . '</a>';

      $button_strip[$key] = $buttons[$key];
   }

   if (empty($button_strip))
      return '<td>&nbsp;</td>';

   echo '
      <td class="', $direction == 'top' ? 'main' : 'mirror', 'tab_' , $context['right_to_left'] ? 'last' : 'first' , '">&nbsp;</td>
      <td class="', $direction == 'top' ? 'main' : 'mirror', 'tab_back">', implode(' &nbsp;|&nbsp; ', $button_strip) , '</td>
      <td class="', $direction == 'top' ? 'main' : 'mirror', 'tab_' , $context['right_to_left'] ? 'first' : 'last' , '">&nbsp;</td>';
}

?>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1648762-4");
pageTracker._initData();
pageTracker._trackPageview();
</script>
Title: Re: Google Analytics changes formatting - why?
Post by: Harro on January 20, 2008, 01:12:54 PM
You added it at the wrong place.
It should go right before the </body> tag.

And try this code (or you'll get parse errors):

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1648762-4");
pageTracker._initData();
pageTracker._trackPageview();
</script>

Title: Re: Google Analytics changes formatting - why?
Post by: mvc on January 21, 2008, 12:06:14 AM
I think that did it.  I had the code where you suggested but I got all kinds of errors and could only get it to work at the end.  I used your code and now it works.  Thanks much!! :)