FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Google Analytics
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Google Analytics [message #163150] Sun, 03 October 2010 04:31 Go to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
I just tried inserting my analytics code in the footer file and got the following error after rebuilding the theme:

T_CONSTANT_ENCAPSED_STRING on line 492

Line 492 of the index.php file is:

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

Everything looks ok to me. I tried breaking out the code but had the same issue. Anyone else seen this before I spend to much time looking into it?
Re: Google Analytics [message #163151 is a reply to message #163150] Sun, 03 October 2010 08:11 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Difficult to say.
I don't see the code in question on your site.
Can you please post steps to reproduce or point us to a page with the problem?
Re: Google Analytics [message #163152 is a reply to message #163151] Sun, 03 October 2010 08:56 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
You have to backslash the thingimabobs

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

has to be

var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);


Re: Google Analytics [message #163156 is a reply to message #163152] Sun, 03 October 2010 14:34 Go to previous messageGo to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
I tried echo first and after a quick search found the \ suggestion. Neither one worked but incase I was crazy/tired I tried again.

var s = document.getElementsByTagName('\script\')[0]; s.parentNode.insertBefore(ga, s);

Gave me the same error as before. The footer section from the index.php file:

Quote:
</script>
<div style="text-align: center;">
<script type="text/javascript"><!--
google_ad_client = "pub-89928376906811";
/* 728x90, created 9/23/10 */
google_ad_slot = "1253056536";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
<br>
</b><b>.::</b> Didn't Find What You Are Looking For? Visit Our Parent
Site <a href="http://volvospeed.com/vs_forum/">Volvospeed</a> <b>::.</b>
<b><br>.::</b> <a href="mailto:webmaster(at)volvospeed(dot)com">Contact</a> <b>::</b>
<a href="index.php?t=index&amp;">Home</a> <b>::.<br>
</td></tr></table>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-315562-4']);
_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') + <?php echo google-analytics.com/ga.js';
var s = document.getElementsByTagName('\script\')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>


I changed the account numbers but other wise thats whats causing the error. I am not leaving it like that as it breaks the board. So saving grace is it is easy to roll back and get the board working again.
Re: Google Analytics [message #163157 is a reply to message #163150] Sun, 03 October 2010 14:57 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
var s = document.getElementsByTagName('\script\')[0]; s.parentNode.insertBefore(ga, s);

is not correct

var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);

is correct (apostrophe on the wrong place)

You have to backslash all the apostrophes if you place them in footer.

Like this
</script>
<div style="text-align: center;">
<script type="text/javascript"><!--
google_ad_client = "pub-89928376906811";
/* 728x90, created 9/23/10 */
google_ad_slot = "1253056536";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
<br>
</b><b>.::</b> Didn't Find What You Are Looking For? Visit Our Parent
Site <a href="http://volvospeed.com/vs_forum/">Volvospeed</a> <b>::.</b>
<b><br>.::</b> <a href="mailto:webmaster(at)volvospeed(dot)com">Contact</a> <b>::</b>
<a href="index.php?t=index&amp;">Home</a> <b>::.<br>
</td></tr></table>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'UA-315562-4\']);
_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\') + <?php echo google-analytics.com/ga.js\';
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>


Re: Google Analytics [message #163158 is a reply to message #163157] Sun, 03 October 2010 14:59 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
You can also not use <?php to execute PHP code within the template

Re: Google Analytics [message #163159 is a reply to message #163158] Sun, 03 October 2010 15:00 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
Why you get the problem is because when the forum compiles the theme, it will interpret the apostrophes as endings of a PHP argument/string, whatever, so to ensure that the forum does not execute them in PHP mode, you tell PHP that they are just symbols and nothing the engine needs to interpret. You do this by backslashing them.

Re: Google Analytics [message #163160 is a reply to message #163159] Sun, 03 October 2010 15:13 Go to previous messageGo to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
I typoed it today apparently but thats what I had last night. After a rebuild of the theme I get:


Quote:
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/s40con/public_html/forum/theme/volvospeed/index.php on line 488

Parse error: syntax error, unexpected T_VAR in /home/s40con/public_html/forum/theme/volvospeed/index.php on line 489
Re: Google Analytics [message #163161 is a reply to message #163160] Sun, 03 October 2010 15:29 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
Alright, it wasn't the apostrophes, you can actually use them in the footer - its the <?php thing that messes you up

Maybe this works?
</script>
<div style="text-align: center;">
<script type="text/javascript">
<!--
google_ad_client = "pub-89928376906811";
google_ad_slot = "1253056536";
google_ad_width = "728";
google_ad_height = "90";
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
<br>
</b><b>.::</b> Didn't Find What You Are Looking For? Visit Our Parent
Site <a href="http://volvospeed.com/vs_forum/">Volvospeed</a> <b>::.</b>
<b><br>.::</b> <a href="mailto:webmaster(at)volvospeed(dot)com">Contact</a> <b>::</b>
<a href="index.php?t=index&amp;">Home</a> <b>::.<br>
</td></tr></table>

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'UA-315562-4\']);
_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>


Re: Google Analytics [message #163162 is a reply to message #163161] Sun, 03 October 2010 15:31 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
I also think google updated their tracking code, this is what i found at a quick quick glance:
    <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">
    try {
    var pageTracker = _gat._getTracker("UA-xxxxxx-x");
    pageTracker._trackPageview();
    } catch(err) {}
    </script>


Re: Google Analytics [message #163163 is a reply to message #163162] Sun, 03 October 2010 15:48 Go to previous messageGo to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
Quote:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'UA-315562-4\']);
_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>


Did the trick. As for rhw format, thats the formatt I got off google this morning. The old code went in the head, and the newer one they suggest goes in the body. Either way that di the trick. THANK YOU!
Re: Google Analytics [message #163164 is a reply to message #163163] Mon, 04 October 2010 06:05 Go to previous messageGo to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
Well it did not cause any errors, but its also not working.
Works at:
http://s40concepts.net/
But not broken out at http://s40concepts.net/forum/
Re: Google Analytics [message #163165 is a reply to message #163164] Mon, 04 October 2010 08:36 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
Yes, my fault, I messed up a quote

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'UA-315562-4\']);
_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>


should work


[Updated on: Mon, 04 October 2010 08:36]

Report message to a moderator

Re: Google Analytics [message #163166 is a reply to message #163165] Mon, 04 October 2010 14:32 Go to previous messageGo to next message
Volvospeed is currently offline  Volvospeed   United States
Messages: 17
Registered: September 2010
Karma: 0
Junior Member
Thats the way I orginally had it which gives you this:

Quote:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/s40con/public_html/forum/theme/volvospeed/index.php on line 488

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/s40con/public_html/forum/theme/volvospeed/index.php on line 488

Parse error: syntax error, unexpected T_VAR in /home/s40con/public_html/forum/theme/volvospeed/index.php on line 489


I would have thought a ton of people here would be running analytics
Re: Google Analytics [message #163169 is a reply to message #163166] Mon, 04 October 2010 16:48 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Mail me an admin userid/password to your forum so I can have a look.

PS: I've just enabled Google Analytics on this forum and it was a quick and painless process.
Re: Google Analytics [message #163170 is a reply to message #163169] Mon, 04 October 2010 17:12 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
Just use the damn quote likes naudefj has on this form hehe. I use very old analytics code, so couldn't copy mine.

Edit: I have strong hate for apostrophes, they always cause me trouble, I am such a noob =(

<script type="text/javascript">
// Google analytics.
  var _gaq = _gaq || [];
  _gaq.push(["_setAccount", "UA-315562-4"]);
  _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>


[Updated on: Mon, 04 October 2010 17:26]

Report message to a moderator

Re: Google Analytics [message #163171 is a reply to message #163170] Mon, 04 October 2010 17:19 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
On a side note, the Google_analytics.plugin will be an interesting angle in FUDforum 3.0.2.
icon14.gif  Re: Google Analytics [message #166376 is a reply to message #163152] Tue, 29 November 2011 02:31 Go to previous messageGo to next message
PaulinoAlo is currently offline  PaulinoAlo
Messages: 2
Registered: September 2011
Karma: 0
Junior Member
It's great information to analyse google analytics.
Thanks!!!!!


PaulinoAlo
Re: Google Analytics [message #167099 is a reply to message #166376] Mon, 23 April 2012 06:30 Go to previous messageGo to next message
Mac John is currently offline  Mac John
Messages: 3
Registered: April 2012
Karma: 0
Junior Member
Same problem happens with me. But i have solved it to put analytic in Meta, For al lstatic pages not in PHP.
Re: Google Analytics [message #167100 is a reply to message #167099] Mon, 23 April 2012 06:38 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
It's much easier to just enable the provided Google analytics plugin.
Re: Google Analytics [message #167101 is a reply to message #167100] Mon, 23 April 2012 06:43 Go to previous messageGo to next message
Mac John is currently offline  Mac John
Messages: 3
Registered: April 2012
Karma: 0
Junior Member
Is there any tutorial about Google plugin?
Because i am newbie and cant better understand without tutorial

Thanks
Re: Google Analytics [message #167102 is a reply to message #167101] Mon, 23 April 2012 07:47 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Step 1: Navigate to the Plugin Manager ACP.
Step 2. Ensure that the plugin system is enabled.
Step 3. Enable the plugins you want.
Re: Google Analytics [message #167434 is a reply to message #167102] Tue, 19 June 2012 11:04 Go to previous message
Anonymous
I am also looking for google plugin tutorial...help required plz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Adding javascript code to a php doc
Next Topic: Problems getting LDAPS to work
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 22:30:25 GMT 2024

Total time taken to generate the page: 0.02735 seconds