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' }));