News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Font issue when adding code to index.template.php

Started by mnporter2001, March 12, 2014, 11:00:22 AM

Previous topic - Next topic

mnporter2001

Hi all
As per title im trying to add analyitics code to index.template.php but when i do that although google analytics work, it makes my forum font a lot larger ?

I thought it was perhaps the code from google, but histats is the same.

The font jumps around 2pts when ever i alter the php page ?

Any idea's and thanks to anyone that replies it will be appreciated

Cheers
Mark

kat

Welcome, Mark!

Can you paste the code that you're using, inside [code][/code] tags?

mnporter2001

Quote from: K@ on March 12, 2014, 11:30:01 AM
Welcome, Mark!

Can you paste the code that you're using, inside [code][/code] tags?

Hi there and thanks for your response, I have also provided SS so you can see what I mean



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-48901800-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>




After code added I get this:



Thanks
Mark


mnporter2001

Quote from: Illori on March 12, 2014, 11:58:49 AM
why dont you try http://custom.simplemachines.org/mods/index.php?mod=2210 ?

I tried that mod  ;D

But as im not using the default theme it didn't work, and there was no check boxes (As there is on some mods) to update specific themes all it does is the default one  :(

But thanks for the reply

Cheers
Mark

kat

OK, I'm gonna take a wild stab in the dark, here...

google-analytics.com/ga.js is, obviously, out of your control. So, if that script defines text sizes and doesn't close those, you're stuck. I'd assume that, after that file's called, you'd need to redefine the text sizes.

I could well be wrong, though...

mnporter2001

Yeah pretty much what i thought,  but then if i use histats coed it does the same and increases the font size.

Is there another file i can add the analytics code to ?

Or perhaps and ive just thought as im typing perhaps i could create a file called stats.php of something and just <include> it in the file ?

I shall try that and report back

Cheers
Mark

mnporter2001

Yep that solved it.

So if anyone else has this issue follow these steps

Create a php file, i called mine ana.php and it looks like this:

<?php
?>


<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


Then open up your index.template.php file and right at the foot of the page after the ?> add this:

<?php include("ana.php"); ?>

Add the ana.php to the theme root, example mine is /wsitechat.com/Themes/Astonished/ana.php

Of coarse you may have called your php file something other than ana.php so just change that to what ever you called yours.

I hope this helps someone

Thanks
Mark

Chen Zhen

That is not really a proper way of doing it.

Put the attached file into /Themes/default/scripts


You could just call the function within some javascript tags (after the <head> tag) but with this example I will use body onload.
Edit your custom theme (or default) template file:
File: ../Themes/CUSTOM_THEME/index.template.php
Find (or similar):

<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>


Add after the above code:

<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/google_analytics.js?fin20"></script>


Find this within the same file:

<body>


replace with:

<body onload="smf_google_analytics();">

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Kindred

and do note....    if the original way that you included the google code was to drop it in after the closing ?> or before the opening <?   then that explains why your site got screwed up fonts... you can't do it like that.

The google code should be added in the **HEAD** tag, between echo commands, along with the other scripts...


or use the mod that was pointed out.  on 2.0.x, you can install mods into other themes other than the default theme...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

mnporter2001

Im still having some real issues with this, as in I cant get analytics to work.

I have tried Underdog's way and Google didn't report anything

I tried adding the analytics code between this

echo '

Google code

';



And that throw up errors

I went back and re-tried to use the google analiytics mod but it gives me NO template options on where to install it, and just installs in the default theme.


Please help  :)

Has anyone else got any ideas ?

Thanks all for your help so far.

Cheers
Mark

Kays

You Google code contains single quotes and since the php echo is encapsulated in single quotes the single quotes in your code will mess things up. When adding code like you are doing you need to escape the single quotes with a backslash. ( \')


echo '
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push([\'_setAccount\', \'UA-xxxxxxxx-1\']);
  _gaq.push([\'_trackPageview\']);

  (function() {
    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
  })();
  ';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

mnporter2001

Quote from: Kays on March 15, 2014, 09:04:24 AM
You Google code contains single quotes and since the php echo is encapsulated in single quotes the single quotes in your code will mess things up. When adding code like you are doing you need to escape the single quotes with a backslash. ( \')


echo '
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push([\'_setAccount\', \'UA-xxxxxxxx-1\']);
  _gaq.push([\'_trackPageview\']);

  (function() {
    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
  })();
  ';


Thanks for your help Kays.

It nearly worked, the page loaded when i added that code, however it made the page look like it had no style.css file ?

Cheers
Mark

Kays

Where are you adding this code?

Also, do a view source of the page. What does the code look like? Is it properly formatted there?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Chen Zhen

Quote from: -Underdog-
You could just call the function within some javascript tags (after the <head> tag) but with this example I will use body onload.

  .. I suppose you did not understand that statement? Omit any previous edits and ensure the previous attachment is in: /Themes/default/scripts then do the following:

File: ../Themes/CUSTOM_THEME/index.template.php
find:

<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>


add after above code:

<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/google_analytics.js?fin20"></script>
<script type="text/javascript">window.onload = smf_google_analytics();</script>



My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: