• Resolved craftyintentions

    (@craftyintentions)


    Hello! I want to track a custom event when the page loads, if there are certain GET variables in the URL.

    If I place the event code in the jQuery(function()) then it doesn’t track. The only way I could get it to track the event is by adding a mouseover event on the body tag, but obviously this isn’t really that great.

    Is there a better way to fire the events?

    I’m using the following:

    <?php
            if(isset($_GET['ref']) && ($_GET['ref'] == "email" ) {
    
                $freq = (isset($_GET['freq'])) ? $_GET['freq'] : "";
                $sec = (isset($_GET['sec'])) ? $_GET['sec'] : "";
            ?>
                <script type="text/javascript">
    
                    var loginTrack = "no";
                    jQuery(function() {
                        jQuery('body').on('mouseover', function() {
                            if(loginTrack != "yes") { ss_track(event, 33, "login:email,freq:<?php echo $freq;?>,sec:<?php echo $sec;?>") };
                            loginTrack = "yes";
                        });
    
                    })
    
                </script>
           <?php } ?>

    Ideally I’d like to take out the mouseover event and have the event fire when the page loads… is that possible?

    Thanks,
    Sarah

    http://wordpress.org/extend/plugins/wp-slimstat/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Jason Crouse

    (@coolmann)

    Hi there, have you tried to use the document.ready hook?

    http://api.jquery.com/ready/

    Cheers,
    Camu

    Thread Starter craftyintentions

    (@craftyintentions)

    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

    Plugin Contributor Jason Crouse

    (@coolmann)

    What’s the URL?

    Thread Starter craftyintentions

    (@craftyintentions)

    The URL is http://www.snowfaerie.co.uk/

    Thanks,
    Sarah

    Plugin Contributor Jason Crouse

    (@coolmann)

    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

    Thread Starter craftyintentions

    (@craftyintentions)

    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

    Thread Starter craftyintentions

    (@craftyintentions)

    Whoops, sorry, I didn’t see the “mark as resolved” button. Ticked it now!

    Plugin Contributor Jason Crouse

    (@coolmann)

    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

    Thread Starter craftyintentions

    (@craftyintentions)

    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

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Event tracking page page load not working’ is closed to new replies.