Statcounter

Started by sky23, March 25, 2019, 11:01:31 AM

Previous topic - Next topic

sky23

Statcounter Code

Maybe this is of help for others:

You put the code in "index.template.php"
after the closing tag at the very end.

if you put it before, it throws errors.

Doug Heffernan

Quote from: sky23 on March 25, 2019, 11:01:31 AM
Statcounter Code

Maybe this is of help for others:

You put the code in "index.template.php"
after the closing tag at the very end.

if you put it before, it throws errors.

Can you please elaborate a little further? What code?

sky23

If you register (free) on https://statcounter.com, your visitors will be counted, thats all.

For that to work, they will give you your unique "code", which you have to implement.




Kindred

and no....   just dropping it in at the end of index.template.php is pretty much guaranteed to be the wrong location as well.
Сл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."

sky23

So you can tell me then, why it's working and the support of Statcounter recommended it this way, Kindred?

Btw, SMf never made it to Statcounter, they have over 70 Boards/Forums to pick the Installation way from, but SMF is off the hook,
i'm sure you know the answer, right?

And can you tell us the right location instead?  8)

Support Answer:
re: re: Help installing code with smf 2.1rc1

Hello,

Its perfect, I see real-time stats are been recorded:

https://statcounter.com/xxxxxxxxxx/visitor/

No further action is needed.

Sincerely

Tarak
StatCounter Team


Kindred

just because it's working does not mean it's the correct location.

There are a number of things that will "work" but are working despite bad coding practices.... and dropping that at the end of the file is a bad coding practice and results in technically invalid HTML


as a matter of fact, the statcounter page itself tells you where to put it
https://statcounter.com/default/

and that is **NOT** "at the end of the index.template.php file.
You should be putting the code within the echo, just before the closing body tag (step 4 on the stat counter page which describes how to implement)



As for why there is no SMF mod/api for it...  probably because no one ever considered it important or interesting enough to build - especially since it's a paid service.
Сл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."

Sesquipedalian

Quote from: Kindred on March 25, 2019, 01:38:59 PM
As for why there is no SMF mod/api for it...  probably because no one ever considered it important or interesting enough to build - especially since it's a paid service.

That and the fact that SMF tracks a number of stats itself.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Biology Forums

Find </body> and place the code before it.

Kindred

Quote from: Kindred on March 25, 2019, 01:38:59 PM
You should be putting the code within the echo, just before the closing body tag (step 4 on the stat counter page which describes how to implement)

Quote from: Study Force on March 26, 2019, 01:25:34 AM
Find </body> and place the code before it.

yes, that's what I said
Сл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."

sky23

The Standard configuration i've done before, not working, my above is working, for me all what counts.
The way to put the code in, was on advice of statcounter...

By my opinion this should be a feature in the Admin section, to put counter/stats in.
It would be more userfriendly i guess. Google search is full of requests how to put stats in SMF...

And Statcounter is free, in the basic version, only if somebody want to have special features with increasing the storage log files, they charge for it, understandable.


Kindred

500 Up to 250,000 monthly page views    FREE


Many of my sites will exceed that in any single month.

And we do not incorporate things like this in SMF because
1- we already have the most important stats built in.
2- we don't include 3rd party connections, if it can be avoided...  because when the 3rd party then changes the API, we have to make a whole new release outside of our development process.




and, even if you continue to insist on using the wrongly placed code -- hopefully others who choose to use this service would read this and put it in the correct place.
Сл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."

Arantor

Quote from: sky23 on March 26, 2019, 01:27:50 PM
The Standard configuration i've done before, not working, my above is working, for me all what counts.
The way to put the code in, was on advice of statcounter...

By my opinion this should be a feature in the Admin section, to put counter/stats in.
It would be more userfriendly i guess. Google search is full of requests how to put stats in SMF...

And Statcounter is free, in the basic version, only if somebody want to have special features with increasing the storage log files, they charge for it, understandable.



I just suspect you haven't found what it broke yet, and won't know about the misreporting it will do.

sky23

Quote from: Kindred on March 26, 2019, 02:04:55 PM
500 Up to 250,000 monthly page views    FREE


Many of my sites will exceed that in any single month.

And we do not incorporate things like this in SMF because
1- we already have the most important stats built in.
2- we don't include 3rd party connections, if it can be avoided...  because when the 3rd party then changes the API, we have to make a whole new release outside of our development process.

and, even if you continue to insist on using the wrongly placed code -- hopefully others who choose to use this service would read this and put it in the correct place.

So many answer's....all vague..Kindred....
Build-in Stats? Could you specify?
https://www.simplemachines.org/community/index.php?topic=518093.20


sky23

Quote from: Arantor


I just suspect you haven't found what it broke yet, and won't know about the misreporting it will do.

I MADE A FRESH NEW INSTALLATION TO 2.1RC1, what more can i say?????

Kindred

sky....   it doesn't matter if it was a fresh installation or not... the fact is that putting the javascript code at the very end of the index.template.php file means that you put it in the wrong location.

Your page is invalid html because the javascript is being called AFTER the closing body tag...   which means that there may be errors... there may be errors in how the stat javascript reports, as well.

in reality, you should put it in the location that the statcounter website actually instructs you to put it...  just before the </body> tag.

Since SMF uses PHP and calls html in echo statements, that means that you also can't just "paste" it in there - else you will get parse errors.
You have to take the javascript and put it within the echo statement that includes the </body> -- and you may have to escape single quotes within the javascript, depending on what their code actually looks like.

In other words -- it's not just a simple cut and paste --- and as we have been trying to tell you, you put it in the wrong place.
Сл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."

sky23

#16
Yes Kindred, Illori, all right what you wrote.

I checked a couple of hours, why this Standard configuration gave me errors by errors and the other (at the very end of the index.template.php) not.

Found nothing what could have been broken or preventing....etc..

So i went back to this "Code Website checker" on my account with Statcounter, should have done that at the very beginning, haha, et voila: after this Code-checker gaves me warning again, like installation went wrong...i checked if this is really so by checking their own real time tracking. No! It wasn't!
All counting was correctly.
I think their support checked with their own installation-checker as well...

Damn Statcounter checker, hahaha, amazing sometimes all....sorry to bring this in here, but maybe so or so it will give all the "searchers' a little hint anyway.

Attached a sample like it should be, search Statcounter in the index template.

Kindred

ummm.... no, still incorrect.

according to the instructions, it should not go there (and you also have hxxp and [nonactive] in your URL, which is wrong)

you are also using joomla site stats (??)....

finally.... you are using http... which means your site will throw a mixed security error message if you are using https for your actual site.

Code (put this code...) Select

echo '
<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=6674432;
var sc_invisible=1;
var sc_security="c5ceff80";
</script>

<script type="text/javascript"
src="https:www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="joomla site stats"
href="https:statcounter.com/joomla/" target="_blank"><img
class="statcounter"
src="https:c.statcounter.com/6674432/0/c5ceff80/1/"
alt="joomla site stats" ></a></div></noscript>
<!-- End of StatCounter Code --> ';


Code (just before this code) Select

echo '
</body></html>';
Сл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."

sky23

Hi Kindred, not my own index.template.php, i just copied it from there: https://www.simplemachines.org/community/index.php?topic=518093.20

and it worked

Here my own:

function template_html_below()
{
   // Load in any javascipt that could be deferred to the end of the page
   template_javascript(true);

   echo '
<!-- Default Statcounter code for xxxxxx.com
http://xxxxxxx.com/ -->
<script type="text/javascript">
var sc_project="xxxxxxxxxx;
var sc_invisible=1;
var sc_security="xxxxxxxxx";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js"
async></script>
<noscript><div class="statcounter"><a title="Web Analytics
Made Easy - StatCounter" href="https://statcounter.com/"
target="_blank"><img class="statcounter"
src="https://c.statcounter.com/xxxxxxxxx/0/xxxxxxxxxx/1/"
alt="Web Analytics Made Easy -
StatCounter"></a></div></noscript>
<!-- End of Statcounter Code -->
</body>
</html>';

Kindred

in that case, yes.... it looks like you put it in the correct place now. :)
Сл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."

Advertisement: