Javascript tracker 2.4.2 problem with tracking structured events? ( trackStructEvent)

221 views
Skip to first unread message

LPG

unread,
Jun 28, 2015, 2:23:37 PM6/28/15
to snowpl...@googlegroups.com
I'm wondering if there is an issue with snowplow 2.4.2, or the documentation. Can someone please provide a code example that would work with a button click?

I've set up 'specific events', however I don't see any of them appearing in my logs. For example I want a button to trigger an event.

$(document).on('click', '#test', function() { 
    
      window.snowplow('trackStructEvent', 'test', 'click');


When this button is clicked I will see only a 'e=pv' event being triggered client side (in the GET query string). But I don't see any 'e=se' data going out in the GET request.
What am I doing wrong?

See the full example HTML below:

<html>
<head>
  <script type="text/javascript">
  ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
  p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
  };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
  n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.4.2/sp.js","snowplow"));
  window.snowplow('newTracker', 'cf', 'subdomain.domain.com', { // Initialise a tracker
    appId: 'TEST-SITE-ID'
  });
  
  window.snowplow('trackPageView');
  
  </script>

  
  <script type="text/javascript">
    $(document).on('click', '#test', function() { 
    
      window.snowplow('trackStructEvent', 'test', 'click');
      
    });
  </script>


</head>
<body>
  <h1>Test</h1>
  <button id="test">Test</button>
</body>  
</html>


Message has been deleted

Robert Kingston

unread,
Jun 29, 2015, 4:01:19 AM6/29/15
to snowpl...@googlegroups.com
Looks fine to me, LPG.

Have you setup a collector? You need to update this to your collector hostname:

  window.snowplow('newTracker', 'cf', 'subdomain.domain.com', { // Initialise a tracker

Have you checked the console?

Remember to look out for HTTP requests in Chrome:

Fred Blundun

unread,
Jun 29, 2015, 4:25:37 AM6/29/15
to snowpl...@googlegroups.com
Hi LPG,

The JavaScript Tracker stores events that have failed to send in a localStorage queue. If "subdomain.domain.com" is not a real collector, then the initial page view will be queued in localStorage and all subsequent structured events will be queued after it. Each time you attempt to send a structured event, the tracker will attempt to empty the queue, starting with the first event in the queue, which is the page view event. But this always fails, and the tracker gives up on sending the rest of the enqueued events (until the next time you attempt to send an event). This could be causing the repeated page view events you see - the enqueued page view event is blocking the structured events from being sent.

Regards,
Fred

If "subdomain.domain.com" is not a real collector, then 

LPG

unread,
Jun 29, 2015, 10:12:31 PM6/29/15
to snowpl...@googlegroups.com
Fred Thanks for the feedback. 
Yes now I see in localStorage there's a backlog of events.
I'm experimenting with a DIY collector set-up, with my own server. I am successfully receiving the first event in my DB (e=pv). There are no failures, errors, or timeouts.

So, how does the tracker "decide" the event was successful? How do I make sure it keeps sending subsequent events?

Thanks in advance!

Grzegorz Ewald

unread,
Jun 30, 2015, 3:40:08 AM6/30/15
to snowpl...@googlegroups.com
Hi LPG,
The tracker checks the http connection status of the GET request. If it is not 200, it saves event to local storage and tries to send all the buffered events later (on new snowplow object instance creation).

Fred Blundun

unread,
Jun 30, 2015, 5:46:12 AM6/30/15
to snowpl...@googlegroups.com
Hi LPG,

As Gregorz says, the JS Tracker checks the status of the request for an event. If the status is not 200-399, it is seen as a failure and the Tracker won't attempt to send further enqueued events (until the next time you try to fire an event).

One other thing to note. If events saved in localStorage in a previous session are to be sent, then the Snowplow function name and the tracker namespace ("snowplow" and "cf" in your example above) and the method (GET or POST) must all be the same as they were in the session where the events were originally created. (If you look at localStorage, you can see how these are incorporated into the queue name.)

Regards,
Fred

--
You received this message because you are subscribed to the Google Groups "Snowplow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snowplow-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LPG

unread,
Jul 12, 2015, 7:25:14 PM7/12/15
to snowpl...@googlegroups.com
Thanks for the feedback guys.
The only comment I have is that it is a bit frustrating to discover these errors if the tracker fails silently. I'm guessing it's intentional that the tracker should fail silently, but perhaps there should be a dev version that fails with verbosity. 
Or maybe it exists and I'm missing it?

Alex Dean

unread,
Jul 12, 2015, 7:30:27 PM7/12/15
to snowpl...@googlegroups.com

Yes, it's by design. We have a milestone to add a debug mode to the tracker to help in these kinds of situation:

https://github.com/snowplow/snowplow-javascript-tracker/milestones/Debug%20mode

Cheers,

Alex

--
Reply all
Reply to author
Forward
0 new messages