Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: ccheryld on September 24, 2014, 03:22:35 PM

Title: installing statcounter code/parse error
Post by: ccheryld on September 24, 2014, 03:22:35 PM
When I try to add the Statcounter Code into my template before the    </body></html>';
I get
The file you tried to save generated the following error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in index.template.php on line 344


How can I insert the code correctly?

The code is

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=10046023;
var sc_invisible=1;
var sc_security="6d13d50c";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="site stats"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/10046023/0/6d13d50c/1/"
alt="site stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 03:28:09 PM
Telling us which line is the 344 would be helpful ;)
Title: Re: installing statcounter code/parse error
Post by: ccheryld on September 24, 2014, 03:47:32 PM
This is the beginning of line 331

function template_html_below()
{
   global $context, $settings, $options, $scripturl, $txt, $modSettings;

   echo '

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=10046023;
var sc_invisible=1;
var sc_security="6d13d50c";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure [nofollow]." : "http://www [nofollow].");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="site stats"
href="http://statcounter.com/ [nofollow]" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/10046023/0/6d13d50c/1/ [nofollow]"
alt="site stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</body></html>';
}
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 04:41:54 PM
Try this:
Code (find) Select

var sc_security="6d13d50c";


Code (replace) Select

var sc_security=6d13d50c;


Since the former code doesn't have the " I am just guessing since I am not a coder. ;)
Title: Re: installing statcounter code/parse error
Post by: ccheryld on September 24, 2014, 05:10:29 PM
thanks,but didn't take..same error.
Title: Re: installing statcounter code/parse error
Post by: JBlaze on September 24, 2014, 05:31:22 PM
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=10046023;
var sc_invisible=1;
var sc_security="6d13d50c";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type=\'text/javascript\' src='" +
scJsHost+
"statcounter.com/counter/counter.js\'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="site stats"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/10046023/0/6d13d50c/1/"
alt="site stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->


Escaped all the apostrophes that were causing the parse error. PHP uses ' or " to signify the start and end of a string. In this case, since echo was followed by an apostrophe, that means any apostrophes that are not signifying the end of a string must be escaped using a backslash.
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 05:33:39 PM
I was on the right track with those apostrophes xD
Title: Re: installing statcounter code/parse error
Post by: ccheryld on September 24, 2014, 06:01:04 PM
same error
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 06:29:18 PM
At least post which line :/ help us to help you :)
Title: Re: installing statcounter code/parse error
Post by: Burke ♞ Knight on September 24, 2014, 06:32:15 PM
I install the StatCounter code in all my sites, without editing the code.
Editing out the code, can cause more issues than you think, the way that statcounter's setup does.

Now, when got the code, which did you select?
I always select to get the default, as they add stuff to the codes for blogs, CMS's, etc.
Title: Re: installing statcounter code/parse error
Post by: JBlaze on September 24, 2014, 06:35:09 PM
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=10046023;
var sc_invisible=1;
var sc_security="6d13d50c";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type=\'text/javascript\' src=\'" +
scJsHost+
"statcounter.com/counter/counter.js\'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="site stats"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/10046023/0/6d13d50c/1/"
alt="site stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->


I missed one. Try it now.
Title: Re: installing statcounter code/parse error
Post by: Burke ♞ Knight on September 24, 2014, 07:00:20 PM
Quote from: BurkeKnight on September 24, 2014, 06:32:15 PM
I install the StatCounter code in all my sites, without editing the code.
Editing out the code, can cause more issues than you think, the way that statcounter's setup does.

Now, when got the code, which did you select?
I always select to get the default, as they add stuff to the codes for blogs, CMS's, etc.

Please read this, as the default code is what works, and I have had it on well over 12 SMF forums.
Also, editing StatCounter's coding, can CAUSE count errors as well as connection issues with their servers, meaning that you more likely will not get the correct stats, making the whole thing basically useless.

Do note, StatCounter is already basically useless, as if anyone has an ad-blocker for their browser (more likely 95% of people) then it blocks StatCounter.
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 07:10:33 PM
Quote from: BurkeKnight on September 24, 2014, 07:00:20 PM
Do note, StatCounter is already basically useless, as if anyone has an ad-blocker for their browser (more likely 95% of people) then it blocks StatCounter.
Seriously?  :o
Title: Re: installing statcounter code/parse error
Post by: Burke ♞ Knight on September 24, 2014, 07:16:13 PM
Yep. I only see a few hits on any of my sites, when check the statcounter stats, yet, according to my server stats, as well as even Feedjit, that you all can see on my sites, I get a lot more.

Heck, even the live traffic stats, by Feedjit, gets blocked, 80% of the time.
Title: Re: installing statcounter code/parse error
Post by: ccheryld on September 24, 2014, 07:16:22 PM
I have an ad blocker...but thanks, Zilla...it worked this last time!!!!!
Thanks also to all who responded with help!
Title: Re: installing statcounter code/parse error
Post by: Ninja ZX-10RR on September 24, 2014, 07:17:45 PM
Quote from: BurkeKnight on September 24, 2014, 07:16:13 PM
Yep. I only see a few hits on any of my sites, when check the statcounter stats, yet, according to my server stats, as well as even Feedjit, that you all can see on my sites, I get a lot more.

Heck, even the live traffic stats, by Feedjit, gets blocked, 80% of the time.
Thanks for letting me know, in fact I was planning to put one but not anymore :P