Skip to content

Commit

Permalink
Fix snowplow ecommerce typename conflicts (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
igneel64 authored Mar 12, 2024
1 parent 8715335 commit d8ef9ec
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce",
"comment": "Fix snowplow ecommerce type conflicts",
"type": "none"
}
],
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce"
}
10 changes: 5 additions & 5 deletions plugins/browser-plugin-snowplow-ecommerce/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
ListViewEvent,
Page as PageContext,
Product,
Promotion,
SPPromotion,
Refund,
Transaction,
SPTransaction,
TransactionError,
User as UserContext,
} from './types';
Expand Down Expand Up @@ -109,7 +109,7 @@ export function trackProductListClick(
* @param trackers - The tracker identifiers which the event will be sent to
*/
export function trackPromotionView(
promotionView: Promotion & CommonEcommerceEventProperties,
promotionView: SPPromotion & CommonEcommerceEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { context = [], timestamp, ...promotion } = promotionView;
Expand All @@ -127,7 +127,7 @@ export function trackPromotionView(
* @param trackers - The tracker identifiers which the event will be sent to
*/
export function trackPromotionClick(
promotionClick: Promotion & CommonEcommerceEventProperties,
promotionClick: SPPromotion & CommonEcommerceEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
const { context = [], timestamp, ...promotion } = promotionClick;
Expand Down Expand Up @@ -201,7 +201,7 @@ export function trackRemoveFromCart(
* @param trackers - The tracker identifiers which the event will be sent to
*/
export function trackTransaction(
transaction: Transaction & CommonEcommerceEventProperties,
transaction: SPTransaction & CommonEcommerceEventProperties,
trackers: Array<string> = Object.keys(_trackers)
) {
let totalQuantity = 0;
Expand Down
4 changes: 2 additions & 2 deletions plugins/browser-plugin-snowplow-ecommerce/src/ga4/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Product, Promotion } from '../types';
import { Product, SPPromotion } from '../types';
import { Item, Promotion as GA4Promotion, GA4EcommerceObject } from './types';

interface GA4ItemTransformation {
Expand Down Expand Up @@ -32,7 +32,7 @@ export function transformG4ItemsToSPProducts(
});
}

export function transformGA4PromotionToSPPromotion(promotion: GA4EcommerceObject & GA4Promotion): Promotion {
export function transformGA4PromotionToSPPromotion(promotion: GA4EcommerceObject & GA4Promotion): SPPromotion {
const productIds = promotion.items.map((item) => item.item_id);

return {
Expand Down
6 changes: 3 additions & 3 deletions plugins/browser-plugin-snowplow-ecommerce/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export type Product = {
/**
* Type/Schema for a promotion entity in Ecommerce
*/
export interface Promotion {
export interface SPPromotion {
/**
* The ID of the promotion.
*/
Expand Down Expand Up @@ -193,7 +193,7 @@ export interface Promotion {
/**
* Type/Schema for a transaction entity in Ecommerce
*/
export interface Transaction {
export interface SPTransaction {
/**
* The ID of the transaction
*/
Expand Down Expand Up @@ -296,7 +296,7 @@ export interface TransactionError {
/**
* The transaction object representing the transaction that ended up in an error.
*/
transaction: Transaction;
transaction: SPTransaction;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions plugins/browser-plugin-snowplow-ecommerce/src/ua/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Product, Promotion } from '../types';
import { Product, SPPromotion } from '../types';
import { EEProduct, EEPromo } from './types';

export function transformUAProductsToSPProducts(products: EEProduct[], currency: string): Product[] {
Expand All @@ -18,7 +18,7 @@ export function transformUAProductsToSPProducts(products: EEProduct[], currency:
});
}

export function transformUAPromotionsToSPPromotions(promotions: EEPromo[]): Promotion[] {
export function transformUAPromotionsToSPPromotions(promotions: EEPromo[]): SPPromotion[] {
return promotions.map((promotion) => ({
name: promotion.name,
slot: promotion.position,
Expand Down
20 changes: 15 additions & 5 deletions plugins/browser-plugin-snowplow-ecommerce/test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
TRANSACTION_SCHEMA,
TRANSACTION_ERROR_SCHEMA,
} from '../src/schemata';
import { CheckoutStep, Product, Promotion, Refund, Transaction, TransactionError } from '../src/types';
import { CheckoutStep, Product, SPPromotion, Refund, SPTransaction, TransactionError } from '../src/types';

const extractStateProperties = ({
outQueues: [
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('SnowplowEcommercePlugin events', () => {
});

it('trackPromotionView adds the expected "promotion view" event to the queue', () => {
const promoX: Promotion = {
const promoX: SPPromotion = {
id: '1234',
name: 'promo_winter',
product_ids: ['P1234'],
Expand All @@ -193,7 +193,7 @@ describe('SnowplowEcommercePlugin events', () => {
});

it('trackPromotionClick adds the expected "promotion click" event to the queue', () => {
const promoX: Promotion = {
const promoX: SPPromotion = {
id: '1234',
name: 'promo_winter',
product_ids: ['P1234'],
Expand Down Expand Up @@ -292,7 +292,12 @@ describe('SnowplowEcommercePlugin events', () => {
it('trackTransaction adds the expected "transaction" event to the queue', () => {
const productX: Product = { id: '1234', price: 12, currency: 'EUR', quantity: 4 };
const productY: Product = { id: '12345', price: 25, currency: 'EUR', quantity: 1 };
const transaction: Transaction = { revenue: 45, currency: 'EUR', transaction_id: '12345', payment_method: 'card' };
const transaction: SPTransaction = {
revenue: 45,
currency: 'EUR',
transaction_id: '12345',
payment_method: 'card',
};
trackTransaction({
...transaction,
products: [productX, productY],
Expand Down Expand Up @@ -365,7 +370,12 @@ describe('SnowplowEcommercePlugin events', () => {
error_shortcode: 'CARD_DECLINE',
error_type: 'hard',
};
const transaction: Transaction = { revenue: 45, currency: 'EUR', transaction_id: '12345', payment_method: 'card' };
const transaction: SPTransaction = {
revenue: 45,
currency: 'EUR',
transaction_id: '12345',
payment_method: 'card',
};
trackTransactionError({
...transactionError,
transaction,
Expand Down

0 comments on commit d8ef9ec

Please sign in to comment.