Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding event name in tracking payload overrides all other properties #4

Open
Sov3rain opened this issue Sep 6, 2024 · 2 comments
Open

Comments

@Sov3rain
Copy link

Sov3rain commented Sep 6, 2024

Hi there!

Using this package with Fastify server in Node@20. I'm building all the parameters for tracking my user like this:

const umami = new Umami();

umami.init({
  hostUrl: process.env.UMAMI_HOST,
  websiteId: ...,
  userAgent: req.userAgent.source,
});

const url = new URL(req.url, `${req.protocol}://${req.hostname}`);
const { hostname, pathname } = url;
const language = req.headers["accept-language"];
const { referrer } = req.headers;

umami.track({
  hostname,
  screen: "1920x1080",
  language,
  title: `/Home`,
  url: pathname,
  referrer,
});

This is working just fine, I'm getting all the information in my dashboard. Unfortunately when I add a custom event name, suddenly all the other information are missing, and I get only the event tracking:

umami.track({
  hostname,
  screen: "1920x1080",
  language,
  title: `/Home`,
  url: pathname,
  referrer,
+ name: "My event"
});

I worked around this issue by calling track() twice: once with the generic tracking information and once with my custom event only:

umami.track({
  hostname,
  screen: "1920x1080",
  language,
  title: `/Home`,
  url: pathname,
  referrer,
  name: "Button clicked"
});
umami.track("My event");

I should not be forced to do that, right?
Thanks!

NOTE: I'm importing the Umami class instead of the default import because it doesn't work, I can open another issue if you wish.

@boly38
Copy link
Contributor

boly38 commented Oct 16, 2024

I encounter some trouble using node client + cloud umami website entry too

  • userAgent is only undertaken in umami constructor (I would expect on identify and/or track)
  • it seems event hit do require a page hit just before : that strange for me too

I noticed that to retrieve event custom data, the track event must include "data" attribute like:

const data = {"color": "red"};
event = {url, title, "name": "button-click", data};
await umamiClient.track(event);

(see also gist)


suggestion: I would expect a set of tests that ensure node client library quality:
text context) given a special umami website id (could be provided as action secret), some test could be done for: identify, track, trackEvent with verify of expected result from umami management api. this to ensure industrialized product and follow-up of node client compatibility with umami standalone server and/or cloud evolutions.

  1. build client
  2. send page hit w/ userAgent using node client : verify it using umami management api
  3. send event hit w/ userAgent & w/ custom data using node client : verify it using umami management api
  4. repeat 2) and 3) adding identify call as pre-condition

(lets do 1..4 for umami hosted version + 1..4 for umami cloud version)

@Sov3rain
Copy link
Author

After further investigation (I needed to write a Umami client compatible with Unity 3D, so in C#), I found that the function track() is very misnamed. In fact, internally this function is responsible for 2 different things:

  • Tracking page views by passing only a payload object.
  • Tracking events by passing a string as the first parameter, and an optional object as the second parameter.

This is very un-intuitive and this function should be split into two functions instead:

  • trackPageView()
  • trackEvent()

The documentation should be updated with this informations and some clarification should be made on whether or not a page view tracking should precede a event tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants