Socket
Socket
Sign inDemoInstall

eventfan

Package Overview
Dependencies
13
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.0.5

.devcontainer/devcontainer.json

40

dist/module/client/EventFan.js

@@ -70,3 +70,3 @@ /* eslint-disable default-param-last */

// the destination `isLoaded` property will still be false it won't be called again.
console.warn(`Failed to load destination ${destination.name}`, e === null || e === void 0 ? void 0 : e.message);
console.warn(`Failed to load destination ${destination.name}`, e?.message);
}

@@ -82,5 +82,3 @@ }

if (this.user) {
var _destination$identify;
await ((_destination$identify = destination.identify) === null || _destination$identify === void 0 ? void 0 : _destination$identify.call(destination, this.user));
await destination.identify?.(this.user);
} // Replay all page/track calls in order

@@ -91,13 +89,9 @@

if (historicalEvent.page) {
var _destination$page;
await ((_destination$page = destination.page) === null || _destination$page === void 0 ? void 0 : _destination$page.call(destination, historicalEvent.page));
await destination.page?.(historicalEvent.page);
}
if (historicalEvent.track) {
var _destination$eventMap, _destination$eventMap2, _destination$track;
// Apply the event mapping if it exists on this destination
const mappedEvent = ((_destination$eventMap = destination.eventMappings) === null || _destination$eventMap === void 0 ? void 0 : (_destination$eventMap2 = _destination$eventMap[historicalEvent.track.name]) === null || _destination$eventMap2 === void 0 ? void 0 : _destination$eventMap2.call(_destination$eventMap, historicalEvent.track, this.user)) || historicalEvent.track;
await ((_destination$track = destination.track) === null || _destination$track === void 0 ? void 0 : _destination$track.call(destination, mappedEvent));
const mappedEvent = destination.eventMappings?.[historicalEvent.track.name]?.(historicalEvent.track, this.user) || historicalEvent.track;
await destination.track?.(mappedEvent);
}

@@ -131,9 +125,5 @@ }

await Promise.all(this.loadedDestinations.map(destination => {
var _destination$identify2;
await Promise.all(this.loadedDestinations.map(destination => destination.identify?.(user))); // Call the callback (deprecated)
return (_destination$identify2 = destination.identify) === null || _destination$identify2 === void 0 ? void 0 : _destination$identify2.call(destination, user);
})); // Call the callback (deprecated)
callback === null || callback === void 0 ? void 0 : callback();
callback?.();
}

@@ -173,9 +163,5 @@ /**

await Promise.all(this.loadedDestinations.map(destination => {
var _destination$page2;
await Promise.all(this.loadedDestinations.map(destination => destination.page?.(page))); // Call the callback (deprecated)
return (_destination$page2 = destination.page) === null || _destination$page2 === void 0 ? void 0 : _destination$page2.call(destination, page);
})); // Call the callback (deprecated)
callback === null || callback === void 0 ? void 0 : callback();
callback?.();
}

@@ -213,13 +199,11 @@ /**

this.loadedDestinations.map(destination => {
var _destination$eventMap3, _destination$eventMap4, _destination$track2;
// Apply the event mapping if it exists on this destination
const mappedEvent = ((_destination$eventMap3 = destination.eventMappings) === null || _destination$eventMap3 === void 0 ? void 0 : (_destination$eventMap4 = _destination$eventMap3[trackEvent.name]) === null || _destination$eventMap4 === void 0 ? void 0 : _destination$eventMap4.call(_destination$eventMap3, trackEvent, this.user)) || trackEvent; // Send
const mappedEvent = destination.eventMappings?.[trackEvent.name]?.(trackEvent, this.user) || trackEvent; // Send
return (_destination$track2 = destination.track) === null || _destination$track2 === void 0 ? void 0 : _destination$track2.call(destination, mappedEvent);
return destination.track?.(mappedEvent);
})); // Call the callback (deprecated)
callback === null || callback === void 0 ? void 0 : callback();
callback?.();
}
}

@@ -128,4 +128,2 @@ /* eslint-disable @typescript-eslint/dot-notation */

it("adds the event to history", async () => {
var _page$options;
const eventFan = new EventFan();

@@ -138,3 +136,3 @@ await eventFan.page(mockPage.name, mockPage); // Access the private history property (dynamically to avoid type errors)

expect(page.properties).toBeTruthy();
expect((_page$options = page.options) === null || _page$options === void 0 ? void 0 : _page$options.originalTimestamp).toBeTruthy();
expect(page.options?.originalTimestamp).toBeTruthy();
});

@@ -168,4 +166,2 @@ it("sets the default properties (e.g. url)", async () => {

it("adds the event to history", async () => {
var _options;
const eventFan = new EventFan();

@@ -177,3 +173,3 @@ await eventFan.track(mockTrack.name, mockTrack.properties); // Access the private history property (dynamically to avoid type errors)

expect(privateHistory[0].track.properties).toBe(mockTrack.properties);
expect((_options = privateHistory[0].track.options) === null || _options === void 0 ? void 0 : _options.originalTimestamp).toBeTruthy();
expect(privateHistory[0].track.options?.originalTimestamp).toBeTruthy();
});

@@ -180,0 +176,0 @@ it("forwards the call to each loaded destination", async () => {

@@ -74,4 +74,2 @@ /* eslint-disable no-underscore-dangle */

async track(track) {
var _track$options;
// Drip Track event nested properties must be JSON stringified (but not the top level object).

@@ -87,3 +85,3 @@ // This is not documented anywhere.

this.drip.push(["track", track.name, { ...properties,
occurred_at: (_track$options = track.options) === null || _track$options === void 0 ? void 0 : _track$options.originalTimestamp
occurred_at: track.options?.originalTimestamp
}]);

@@ -90,0 +88,0 @@ }

@@ -9,8 +9,6 @@ /**

}) {
var _properties$products, _properties$products2;
// Note that Drip's version of Liquid templating language doesn't support nested properties or arrays, so we must add
// top-level properties currently for each product.
const productsNumbered = {};
(_properties$products = properties.products) === null || _properties$products === void 0 ? void 0 : _properties$products.forEach((product, key) => {
properties.products?.forEach((product, key) => {
Object.keys(product).forEach(productKey => {

@@ -31,3 +29,3 @@ productsNumbered[`product_${key + 1}_${productKey}`] = product[productKey];

order_id: properties.order_id,
products: (_properties$products2 = properties.products) === null || _properties$products2 === void 0 ? void 0 : _properties$products2.map(i => ({
products: properties.products?.map(i => ({
price: i.price ? i.price * 100 : undefined,

@@ -34,0 +32,0 @@ ...i

export default function orderCompleted({
properties
}) {
var _properties$products, _properties$products2;
// Note that Drip's version of Liquid templating language doesn't support nested properties or arrays, so we must add
// top-level properties currently for each product.
const productsNumbered = {};
(_properties$products = properties.products) === null || _properties$products === void 0 ? void 0 : _properties$products.forEach((product, key) => {
properties.products?.forEach((product, key) => {
Object.keys(product).forEach(productKey => {

@@ -25,3 +23,3 @@ productsNumbered[`product_${key + 1}_${productKey}`] = product[productKey];

order_id: properties.order_id,
products: (_properties$products2 = properties.products) === null || _properties$products2 === void 0 ? void 0 : _properties$products2.map(i => ({
products: properties.products?.map(i => ({
price: i.price ? i.price * 100 : undefined,

@@ -28,0 +26,0 @@ ...i

@@ -56,4 +56,2 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

async identify(user) {
var _traits$address, _traits$address$count, _traits$address2, _traits$address2$city, _traits$address2$city2, _traits$email, _traits$firstName, _traits$lastName, _traits$address3, _traits$address3$stat, _traits$address4;
// Don't run if advancedMapping is disabled

@@ -69,13 +67,13 @@ if (this.config.advancedMapping === false) return;

const advancedMatchingParameters = {
country: (_traits$address = traits.address) === null || _traits$address === void 0 ? void 0 : (_traits$address$count = _traits$address.country) === null || _traits$address$count === void 0 ? void 0 : _traits$address$count.toLowerCase(),
ct: (_traits$address2 = traits.address) === null || _traits$address2 === void 0 ? void 0 : (_traits$address2$city = _traits$address2.city) === null || _traits$address2$city === void 0 ? void 0 : (_traits$address2$city2 = _traits$address2$city.toLowerCase()) === null || _traits$address2$city2 === void 0 ? void 0 : _traits$address2$city2.replace(/\s/g, ""),
country: traits.address?.country?.toLowerCase(),
ct: traits.address?.city?.toLowerCase()?.replace(/\s/g, ""),
db: traits.birthday ? parseInt(traits.birthday.replace(/-/g, "")) : undefined,
em: (_traits$email = traits.email) === null || _traits$email === void 0 ? void 0 : _traits$email.toLowerCase(),
em: traits.email?.toLowerCase(),
external_id: traits.id,
fn: (_traits$firstName = traits.firstName) === null || _traits$firstName === void 0 ? void 0 : _traits$firstName.toLowerCase(),
fn: traits.firstName?.toLowerCase(),
ge: gender,
ln: (_traits$lastName = traits.lastName) === null || _traits$lastName === void 0 ? void 0 : _traits$lastName.toLowerCase(),
ln: traits.lastName?.toLowerCase(),
ph: traits.phone ? parseInt(traits.phone) : undefined,
st: (_traits$address3 = traits.address) === null || _traits$address3 === void 0 ? void 0 : (_traits$address3$stat = _traits$address3.state) === null || _traits$address3$stat === void 0 ? void 0 : _traits$address3$stat.toLowerCase(),
zp: (_traits$address4 = traits.address) === null || _traits$address4 === void 0 ? void 0 : _traits$address4.postalCode
st: traits.address?.state?.toLowerCase(),
zp: traits.address?.postalCode
}; // Re-initialise with advanced matching parameters

@@ -82,0 +80,0 @@

@@ -10,5 +10,3 @@ import { ContentType } from "../../types/shared/GenericFacebookEvent.js";

if (category) {
var _config$categoryToCon;
const extraContentType = (_config$categoryToCon = config.categoryToContent) === null || _config$categoryToCon === void 0 ? void 0 : _config$categoryToCon.find(i => i.from === category);
const extraContentType = config.categoryToContent?.find(i => i.from === category);
if (extraContentType) contentType.push(extraContentType.to);

@@ -15,0 +13,0 @@ }

@@ -5,9 +5,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

}) {
var _properties$products, _properties$products2;
return {
name: "AddPaymentInfo",
properties: {
content_ids: (_properties$products = properties.products) === null || _properties$products === void 0 ? void 0 : _properties$products.map(product => product.product_id),
contents: (_properties$products2 = properties.products) === null || _properties$products2 === void 0 ? void 0 : _properties$products2.map(product => ({
content_ids: properties.products?.map(product => product.product_id),
contents: properties.products?.map(product => ({
id: product.product_id,

@@ -14,0 +12,0 @@ quantity: product.quantity || 1 // Default quantity to 1

@@ -85,8 +85,6 @@ import { DestinationName } from "../DestinationName.js";

async page(page) {
var _page$properties, _page$properties2;
if (this.config.blockPageViewEvent === false) return;
this.gtag("event", "page_view", {
page_title: (_page$properties = page.properties) === null || _page$properties === void 0 ? void 0 : _page$properties.title,
page_location: (_page$properties2 = page.properties) === null || _page$properties2 === void 0 ? void 0 : _page$properties2.url
page_title: page.properties?.title,
page_location: page.properties?.url
});

@@ -93,0 +91,0 @@ }

@@ -6,4 +6,2 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

}) {
var _properties$products;
return {

@@ -15,5 +13,5 @@ name: "add_payment_info",

value: properties.revenue,
items: (_properties$products = properties.products) === null || _properties$products === void 0 ? void 0 : _properties$products.map(formatProduct)
items: properties.products?.map(formatProduct)
}
};
}

@@ -5,4 +5,2 @@ import { formatProduct } from "./checkoutStarted.js";

}) {
var _properties$products;
return {

@@ -12,5 +10,5 @@ name: "view_item_list",

item_list_id: properties.list_id,
items: (_properties$products = properties.products) === null || _properties$products === void 0 ? void 0 : _properties$products.map(formatProduct)
items: properties.products?.map(formatProduct)
}
};
}

@@ -39,5 +39,3 @@ /* eslint-disable no-underscore-dangle */

window.hj = (...args) => {
var _window$hj;
(window.hj.q = ((_window$hj = window.hj) === null || _window$hj === void 0 ? void 0 : _window$hj.q) || []).push(args);
(window.hj.q = window.hj?.q || []).push(args);
};

@@ -44,0 +42,0 @@

@@ -21,3 +21,3 @@ import posthog from "posthog-js";

protected config: PosthogConfig;
posthog: typeof posthog;
posthog: import("posthog-js").PostHog;
constructor(config: PosthogConfig);

@@ -24,0 +24,0 @@ identify(user: User): Promise<void>;

@@ -15,3 +15,3 @@ import RudderStack from "../RudderStack.js";

const res = await destination.identify({});
expect(res.status).toBe(400);
expect(res.status).toBe(404);
});

@@ -18,0 +18,0 @@ });

@@ -27,5 +27,3 @@ import React, { createContext, useEffect, useContext } from "react";

useEffect(() => {
var _props$destinations;
(_props$destinations = props.destinations) === null || _props$destinations === void 0 ? void 0 : _props$destinations.forEach(destination => {
props.destinations?.forEach(destination => {
// Note that EventFan enforces idempotency (not adding a destination twice) so we don't need to here

@@ -32,0 +30,0 @@ eventFan.addDestination(destination);

{
"name": "eventfan",
"version": "2.0.4",
"version": "2.0.5",
"description": "Send analytics events to multiple destinations (Google Analytics, Facebook...).",

@@ -18,5 +18,5 @@ "repository": "https://github.com/alan-cooney/eventfan",

"playwright": "playwright test --config=src/e2e/playwright.config.ts",
"playwrightInstall": "playwright install && playwright install-deps",
"react": "yarn vite --config ./src/e2e/react/vite.config.js",
"test": "./node_modules/.bin/jest",
"browser": "yarn vite --config ./src/e2e/browser/vite.config.js"
"test": "./node_modules/.bin/jest"
},

@@ -29,3 +29,3 @@ "devDependencies": {

"@babel/preset-typescript": "^7.17.12",
"@playwright/test": "^1.22.0",
"@playwright/test": "^1.32.3",
"@sentry/browser": "^6.19.7",

@@ -72,3 +72,3 @@ "@swc/cli": "^0.1.57",

"parcel-plugin-nuke-dist": "^1.0.1",
"playwright": "^1.22.0",
"playwright": "^1.32.3",
"postal-address-field-names": "^1.0.3",

@@ -125,3 +125,3 @@ "prettier": "^2.6.2",

"dependencies": {
"posthog-js": "^1.21.1",
"posthog-js": "^1.52.0",
"uuid": "^8.3.2"

@@ -128,0 +128,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc