npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@comparaonline/event-tracker

v7.4.2

Published

This library it's an interface between any frontend application and some event tracking platforms, currently Snowplow and Tag Manager.

Downloads

2,003

Readme

@comparaonline/event-tracker

npm code style: prettier

This library is an interface between any frontend application and an event tracking platforms.

There's more documentation available for the library in compara's notion

Installation

To install the library in your application use

yarn add @comparaonline/event-tracker

or

npm install @comparaonline/event-tracker

Usage example

After installing the package you can send an event using the function sendEvent. For example, to send an event to snowplow (assuming it was already initialized), you could do it with the following code:

import { endpoints, sendEvent, types } from '@comparaonline/event-tracker/';
import {
  carInsuranceGenerators,
  FormSubmitParams,
} from '@comparaonline/event-tracker/eventGenerators/carInsurance';


const rawFormSubmit: FormSubmitParams = {
  appVersion: '1.0',
  appName: 'test-module',
  countryCode: types.CountryCodeTypes.chile,
  formId: 'asdf',
  formType: types.FormTypes.wizard,
  formSubmitStatus: types.FormStatusTypes.successful,
  funnelType: types.FormRelatedTypes.FunnelTypes.quote,
  formValues: { a: 'asdf', b: 'sdf' },
};
const formSubmit = carInsuranceGenerators.generateFormSubmit(rawFormSubmit);
sendEvent(endpoints.SNOWPLOW_APP, formSubmit);

Or alternatively:

To do the same for tag manager you would need to change the last line of the code to:

sendEvent(endpoints.TAG_MANAGER_APP, eventData);

Endpoints

The endpoints supported by the library are in the object endpoints of the library. The ones currently supported are:

  • SNOWPLOW_APP: the library can initialize snowplow with the functions initializeSnowplow and initializeTracker located in snowplowInitializer. initializeTracker needs an app id as input. The ones supported by the library are in snowplowAppIds and are separated by environment (development or production) and country code (cl,br, co, ar). An example of this would be:
import {
  snowplowInitializer,
  snowplowAppIds
} from "@comparaonline/event-tracker";

initializeSnowplow = (environment, countryCode) => {
  snowplowInitializer.initializeSnowplow();
  snowplowInitializer.initializeTracker(
    snowplowAppIds[countryCode],
    environment
  );
};
  • TAG_MANAGER_APP: currently the library doesn't come with a way to initialize tag manager and it assumes that it exists in the browser.

Migrating from 5.x.x to 6.x.x

  1. Imports: the imports have changed, instead of importing the interfaces of events you need to import eventGenerators, which are functions. These functions are grouped by business unit: carInsurance, travelAssistance, soapBrokerage and leadGen. There are also common eventGenerators which are for any business unit and should be used as preliminary measurements.

    import {
      carInsuranceGenerators,
    } from '@comparaonline/event-tracker/eventGenerators/carInsurance';
  2. Types: most events have types for some fields. These can be imported from the main module

    import { types } from '@comparaonline/event-tracker/';
       
    const rawFormSubmit = {
      appVersion: '1.0',
      appName: 'test-module',
      countryCode: types.CountryCodeTypes.chile,
      formId: 'asdf',
      formType: types.FormTypes.wizard,
      formSubmitStatus: types.FormStatusTypes.successful,
      funnelType: types.FormRelatedTypes.FunnelTypes.quote,
      formValues: { a: 'asdf', b: 'sdf' },
    };
  3. Generate event: previously the library only exported interfaces which where the direct input for sendEvent, now you need to use the previously mentioned event generators before sending the event. The generators receive objects that match the interfaces with the suffix Params (e.g. generateFormSubmit receives objects with the structure of FormSubmitParams)

    const rawFormSubmit: FormSubmitParams = {
      appVersion: '1.0',
      appName: 'test-module',
      countryCode: types.CountryCodeTypes.chile,
      formId: 'asdf',
      formType: types.FormTypes.wizard,
      formSubmitStatus: types.FormStatusTypes.successful,
      funnelType: types.FormRelatedTypes.FunnelTypes.quote,
      formValues: { a: 'asdf', b: 'sdf' },
    };
    const formSubmit = carInsuranceGenerators.generateFormSubmit(rawFormSubmit);
    sendEvent(endpoints.SNOWPLOW_APP, formSubmit);

Publishing a new version

Important: The content to be uploaded is the build from the dist directory. You shouldn't try to publish the root directory.

We use np as part of the publishing process. The recommended way to publish a new version is:

$ npm run np -- [version]

Example

$ npm run np -- 4.0.2

This will test, build, update the package version and commit it. Then, the content of the dist directory will be published to the npm registry.

Publishing package in CI pipeline

The package will be published automatically to npm when the CI pipeline is triggered by the master branch. You need to update the package version in package.json otherwise you will get the following error:

npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@comparaonline%2fevent-tracker - You cannot publish over the previously published versions