Hi there, have you tried to use the document.ready hook?
http://api.jquery.com/ready/
Cheers,
Camu
Hi Camu,
I tried adding:
<script type=”text/javascript”>
jQuery(document).ready(function() {
ss_track(event, 33, “test”)
})
</script>
To the head of my page, so that on every page load, it should log the event, but it’s not logging them. I’m not getting any javascript errors. Do you have any idea why this would be?
I need to use jQuery rather than $, otherwise I get errors.
Thanks,
Sarah
Okay, I see what the problem is. The function ss_track is meant to be used in conjunction with an event (click, mouse_over, focus, etc). In your case, the variable ‘event’ is not defined, and when the function tries to detect the event that triggered the call, doesn’t find anything and exits.
What you want to use is SlimStat.send_to_server (when the DOM is ready):
SlimStat.send_to_server(“id=”+SlimStat._id+”&ty=33&no=test&obr=”+location.pathname);
This can work as a temporary workaround. What we can do is to extend ss_track to not abort the execution if no event is found. Instead, it will record the basic information (numeric identifiers, note (param ‘no’ here above) and page that triggered the call (param ‘obr’ in the code above).
Thank you for your input and for using WP SlimStat!
Cheers,
Camu
Oh FANTASTIC, thank you!
I had to add a timeout to get it to work, but now it is tracking every time.
jQuery(document).ready(function() {
setTimeout(function() { SlimStat.send_to_server("id="+SlimStat._id+"&ty=33&no=test&obr="+location.pathname);
}, 200)
})
Thank you for your speedy response, and for taking the time to look into this for me. Much appreciated.
Thanks,
Sarah
Whoops, sorry, I didn’t see the “mark as resolved” button. Ticked it now!
Hi, Sarah.
we discussed alternative approaches to your problem, and we realized that there’s indeed no need to use SlimStat’s “internal” functions to do what you want. We will have to slightly modify our code, so you will have to wait until the next version is released. At that point you will still use ss_track as described in the FAQs (and in the official documentation, soon), but you will have to attach it to the load event:
<script type="text/javascript">
jQuery(window).on('load', function(e){
if (condition){
SlimStat.ss_track(e, 33, 'ciao');
}
});
</script>
Insert this snippet of code in your HEAD section of the page (after changing/removing the conditional statement) and you should be good to go.
We can send you the new Javascript library, if you want to test it. Contact us at
http://slimstat.getused.to.it/contact-us/
Cheers,
Camu
Hi Camu,
Sorry for the slow reply, I’ve only just seen this.
Thank you for taking the time to look into this further, I’ll definitely try out your new code, and will contact you now.
Thanks,
Sarah