@snowplow/node-tracker v3.0.0 Failing silently

I’ve been working on integrating the new node-tracker into our serve-side application, but have a bit of a problem. The tracker is firing events quite happily, but they are never arriving anywhere else. It’s as if they are just firing into the void!

import {
  tracker as newTracker,
  gotEmitter,
  buildStructEvent,
} from '@snowplow/node-tracker';

  let emitter = gotEmitter(
    collectorUrl,
    'https',
    '443',
    1,
    1,
    null,
    emitterCallback
  );

  let tracker = newTracker([emitter], 'namespace', 'app-id');
  let trackStructEvent = (event) => {
    tracker.track(buildStructEvent(event));
  }

From trawling the docs source code and the short docs that exist right now, this all looks right. tracker.track gets called happily, returns a very nice object. But nothing seems to actually – happen. What’s interesting, tho, is that the emitterCallback is never being fired either.

What is the Very Obvious Thing I am missing?

With the example above, I assume you’re calling trackStructEvent somewhere?

e.g.

trackStructEvent({ category: 'cat', action: 'act' });

A couple of things to check, the collectorUrl shouldn’t contain the protocol, that is defined by the second parameter. Given you’re using https it’s perhaps worth making sure your collector is all good when it comes to SSL and accept requests on 443 (which can be as simple as checking you get a 200 when you go to https://collector.mywebsite.com/com.snowplowanalytics.snowplow/i in your browser).

I’ve just run the below example locally, which is extremely similar to yours, and it seems fine.

What version of Node.js are you running? We only test on LTS releases, so 10, 12 and 14 should be fine (I’ve just tested 10, 12 and 14 with the below).

import { 
  buildPageView, 
  buildStructEvent, 
  gotEmitter, 
  HttpMethod, 
  HttpProtocol, 
  tracker 
} from '@snowplow/node-tracker';

const e1 = gotEmitter(
  '127.0.0.1', // Endpoint
  HttpProtocol.HTTP, // Protocol
  9090, // Port
  HttpMethod.POST, // Method
  1, // Buffer Size
  5, // retries
  undefined,
  function (error, response) {
    // Callback called for each request
    if (error) {
      console.log(error, 'Request error');
    } else {
      console.log('Event Sent');
    }
  }
);

const t = tracker([e1], 'myTracker', 'myApp', false);
t.track(
  buildPageView({
    pageUrl: 'https://www.snowplowanalytics.com',
    pageTitle: 'Index',
    referrer: 'https://www.google.com/',
  })
);
t.track(buildStructEvent({ category: 'cat', action: 'act' }));

Or a little more old school…

const nodeTracker = require('@snowplow/node-tracker');

const e1 = nodeTracker.gotEmitter(
  '127.0.0.1', // Endpoint
  nodeTracker.HttpProtocol.HTTP, // Protocol
  9090, // Port
  nodeTracker.HttpMethod.POST, // Method
  1, // Buffer Size
  5, // retries
  undefined,
  function (error, response) {
    // Callback called for each request
    if (error) {
      console.log(error, 'Request error');
    } else {
      console.log('Event Sent');
    }
  }
);

const t = nodeTracker.tracker([e1], 'myTracker', 'myApp', false);

t.track(
  nodeTracker.buildPageView({
    pageUrl: 'https://www.snowplowanalytics.com',
    pageTitle: 'Index',
    referrer: 'https://www.google.com/',
  })
);
t.track(nodeTracker.buildStructEvent({ category: 'cat', action: 'act' }));

Yeah, calling the function with correct data, and I used that link provided to double check the collector URL. Some small adjustments to just default gotTracker initialization (I think the https and 443 were leftover from just trying stuff – http and 8080 are what we expect) and still no dice. We’re running Node 14, so this sounds like it’s probably an Us Problem with post-collected pipeline happenings.

example:

  let trackStructEvent = (event) => {
    console.log('track that event!')
    console.log(event)
    tracker.track(buildStructEvent(event), contexts);
  };

// outputs
track that event!
{
  action: 'TEST',
  category: 'TEST',
  label: 'TEST',
  property: 'TEST',
  value: 0
}

It might be worth spinning up a snowplow-micro on your machine to test this, quite simple if you’ve got Docker installed and has an easy API to check your events.

The docs are in the README:

For some more micro inspiration: What is Snowplow Micro? - Snowplow Docs

2 Likes