Skip to content

Commit b1322cd

Browse files
committed
Fix snowplow ecommerce typename conflicts (#1296)
1 parent 8715335 commit b1322cd

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce",
5+
"comment": "Fix snowplow ecommerce type conflicts",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce"
10+
}

plugins/browser-plugin-snowplow-ecommerce/src/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
ListViewEvent,
2121
Page as PageContext,
2222
Product,
23-
Promotion,
23+
SPPromotion,
2424
Refund,
25-
Transaction,
25+
SPTransaction,
2626
TransactionError,
2727
User as UserContext,
2828
} from './types';
@@ -109,7 +109,7 @@ export function trackProductListClick(
109109
* @param trackers - The tracker identifiers which the event will be sent to
110110
*/
111111
export function trackPromotionView(
112-
promotionView: Promotion & CommonEcommerceEventProperties,
112+
promotionView: SPPromotion & CommonEcommerceEventProperties,
113113
trackers: Array<string> = Object.keys(_trackers)
114114
) {
115115
const { context = [], timestamp, ...promotion } = promotionView;
@@ -127,7 +127,7 @@ export function trackPromotionView(
127127
* @param trackers - The tracker identifiers which the event will be sent to
128128
*/
129129
export function trackPromotionClick(
130-
promotionClick: Promotion & CommonEcommerceEventProperties,
130+
promotionClick: SPPromotion & CommonEcommerceEventProperties,
131131
trackers: Array<string> = Object.keys(_trackers)
132132
) {
133133
const { context = [], timestamp, ...promotion } = promotionClick;
@@ -201,7 +201,7 @@ export function trackRemoveFromCart(
201201
* @param trackers - The tracker identifiers which the event will be sent to
202202
*/
203203
export function trackTransaction(
204-
transaction: Transaction & CommonEcommerceEventProperties,
204+
transaction: SPTransaction & CommonEcommerceEventProperties,
205205
trackers: Array<string> = Object.keys(_trackers)
206206
) {
207207
let totalQuantity = 0;

plugins/browser-plugin-snowplow-ecommerce/src/ga4/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Product, Promotion } from '../types';
1+
import { Product, SPPromotion } from '../types';
22
import { Item, Promotion as GA4Promotion, GA4EcommerceObject } from './types';
33

44
interface GA4ItemTransformation {
@@ -32,7 +32,7 @@ export function transformG4ItemsToSPProducts(
3232
});
3333
}
3434

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

3838
return {

plugins/browser-plugin-snowplow-ecommerce/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export type Product = {
159159
/**
160160
* Type/Schema for a promotion entity in Ecommerce
161161
*/
162-
export interface Promotion {
162+
export interface SPPromotion {
163163
/**
164164
* The ID of the promotion.
165165
*/
@@ -193,7 +193,7 @@ export interface Promotion {
193193
/**
194194
* Type/Schema for a transaction entity in Ecommerce
195195
*/
196-
export interface Transaction {
196+
export interface SPTransaction {
197197
/**
198198
* The ID of the transaction
199199
*/
@@ -296,7 +296,7 @@ export interface TransactionError {
296296
/**
297297
* The transaction object representing the transaction that ended up in an error.
298298
*/
299-
transaction: Transaction;
299+
transaction: SPTransaction;
300300
}
301301

302302
/**

plugins/browser-plugin-snowplow-ecommerce/src/ua/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Product, Promotion } from '../types';
1+
import { Product, SPPromotion } from '../types';
22
import { EEProduct, EEPromo } from './types';
33

44
export function transformUAProductsToSPProducts(products: EEProduct[], currency: string): Product[] {
@@ -18,7 +18,7 @@ export function transformUAProductsToSPProducts(products: EEProduct[], currency:
1818
});
1919
}
2020

21-
export function transformUAPromotionsToSPPromotions(promotions: EEPromo[]): Promotion[] {
21+
export function transformUAPromotionsToSPPromotions(promotions: EEPromo[]): SPPromotion[] {
2222
return promotions.map((promotion) => ({
2323
name: promotion.name,
2424
slot: promotion.position,

plugins/browser-plugin-snowplow-ecommerce/test/events.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import {
5353
TRANSACTION_SCHEMA,
5454
TRANSACTION_ERROR_SCHEMA,
5555
} from '../src/schemata';
56-
import { CheckoutStep, Product, Promotion, Refund, Transaction, TransactionError } from '../src/types';
56+
import { CheckoutStep, Product, SPPromotion, Refund, SPTransaction, TransactionError } from '../src/types';
5757

5858
const extractStateProperties = ({
5959
outQueues: [
@@ -168,7 +168,7 @@ describe('SnowplowEcommercePlugin events', () => {
168168
});
169169

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

195195
it('trackPromotionClick adds the expected "promotion click" event to the queue', () => {
196-
const promoX: Promotion = {
196+
const promoX: SPPromotion = {
197197
id: '1234',
198198
name: 'promo_winter',
199199
product_ids: ['P1234'],
@@ -292,7 +292,12 @@ describe('SnowplowEcommercePlugin events', () => {
292292
it('trackTransaction adds the expected "transaction" event to the queue', () => {
293293
const productX: Product = { id: '1234', price: 12, currency: 'EUR', quantity: 4 };
294294
const productY: Product = { id: '12345', price: 25, currency: 'EUR', quantity: 1 };
295-
const transaction: Transaction = { revenue: 45, currency: 'EUR', transaction_id: '12345', payment_method: 'card' };
295+
const transaction: SPTransaction = {
296+
revenue: 45,
297+
currency: 'EUR',
298+
transaction_id: '12345',
299+
payment_method: 'card',
300+
};
296301
trackTransaction({
297302
...transaction,
298303
products: [productX, productY],
@@ -365,7 +370,12 @@ describe('SnowplowEcommercePlugin events', () => {
365370
error_shortcode: 'CARD_DECLINE',
366371
error_type: 'hard',
367372
};
368-
const transaction: Transaction = { revenue: 45, currency: 'EUR', transaction_id: '12345', payment_method: 'card' };
373+
const transaction: SPTransaction = {
374+
revenue: 45,
375+
currency: 'EUR',
376+
transaction_id: '12345',
377+
payment_method: 'card',
378+
};
369379
trackTransactionError({
370380
...transactionError,
371381
transaction,

0 commit comments

Comments
 (0)