html hit counter is disrupting my navigation bar links

21 views
Skip to first unread message

Ruth Stephenson

unread,
Jul 25, 2016, 2:52:52 PM7/25/16
to rubyonra...@googlegroups.com
I thought a hit counter would be simple enough as it's a pretty basic
piece of code to insert to a html page, however when I add statcounter
to my rails app, all the navigation links break. Can anyone advise me as
to the best way to insert something like this to my app? It works but
when I click on a nav link, it just displays the hit counter on a blank
page unless I reload the page or , if I use the invisible hit counter,
it displays an empty page for whatever nav link I click.

application.html.erb

<!--
* Statcounter to monitor visitors, etc to my webapp
* @reference https://statcounter.com
-->

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=11051099;
var sc_invisible=0;
var sc_security="0e87dbf6";
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="shopify
analytics" href="http://statcounter.com/shopify/"
target="_blank"><img class="statcounter"
src="//c.statcounter.com/11051099/0/0e87dbf6/0/"
alt="shopify analytics"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->

--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Jul 26, 2016, 1:45:20 AM7/26/16
to Ruby on Rails: Talk
On Monday, July 25, 2016 at 7:52:52 PM UTC+1, Ruby-Forum.com User wrote:
> I thought a hit counter would be simple enough as it's a pretty basic
> piece of code to insert to a html page, however when I add statcounter
> to my rails app, all the navigation links break. Can anyone advise me as
> to the best way to insert something like this to my app? It works but
> when I click on a nav link, it just displays the hit counter on a blank
> page unless I reload the page or , if I use the invisible hit counter,
> it displays an empty page for whatever nav link I click.

Perhaps some sort of interaction with turbolinks?

Fred

Johnny Stewart

unread,
Jul 28, 2016, 4:37:35 AM7/28/16
to rubyonra...@googlegroups.com
Ruth Stephenson wrote in post #1184744:
If it works when you explicitly reload the page it sounds like your new
javascript might not be playing well with turbolinks.

I'd start looking around there, try disabling turbolinks and see if that
makes a difference..

J

Walter Lee Davis

unread,
Jul 28, 2016, 7:43:13 AM7/28/16
to rubyonra...@googlegroups.com

> On Jul 28, 2016, at 4:37 AM, Johnny Stewart <li...@ruby-forum.com> wrote:
>
> I'd start looking around there, try disabling turbolinks and see if that
> makes a difference..

But don't leave it off -- use this as a test to see if that's the problem, and then edit your script to change the event it observes from 'ready' to 'page:change'. The latter is added to the page load sequence by Turbolinks, and it is a catch-all -- it fires on a full reload and a turbolinks page replace -- so you only have to listen to one event to get all types of page "load".

Walter
Reply all
Reply to author
Forward
0 new messages