Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
832a8d5
Implement Ecommerce features
ebongzzang Sep 23, 2020
93c0460
Move Trackable, Tag interface under to Legacy.ts
ebongzzang Sep 23, 2020
9df6920
Add EventTracker.sendAddToCart
ebongzzang Sep 23, 2020
2f8c453
Refactoring project structure
ebongzzang Sep 23, 2020
196fc71
Revert GA Ecommerce implementation, Deprecate GATracker
ebongzzang Sep 25, 2020
a042803
Implement GtagTacker
ebongzzang Sep 25, 2020
aa69e2e
Update sendClick parameters
ebongzzang Sep 28, 2020
86beb0d
Formatting test codes
ebongzzang Sep 28, 2020
6622e2d
Fix comments in EcommerceTracker interface
ebongzzang Sep 28, 2020
239ea9f
Add ViewPromotion Event
ebongzzang Sep 28, 2020
91cd8b6
Update sendAddPaymentInfo
ebongzzang Sep 28, 2020
2263373
Fix GTagTracker.sendImpression
ebongzzang Sep 28, 2020
3f8668a
Update model following newer event spec
ebongzzang Oct 21, 2020
468a7a2
Implement sendBeginCheckout
ebongzzang Oct 21, 2020
7b70401
Update sendSignUp parameter
ebongzzang Oct 22, 2020
0248926
Implement sendScreenView method on gtag, beacon tracker
ebongzzang Oct 22, 2020
1ac7093
Remove ga, beacon, gtag tracker subdirectory
ebongzzang Oct 22, 2020
dabb5b5
Update gtag tracker following ga4 update
ebongzzang Oct 22, 2020
875bfb6
Implement ecommerce tracking methods on Tracker
ebongzzang Oct 22, 2020
485f57e
Fix broken testcase
ebongzzang Oct 22, 2020
dd7c7fd
Implement Ecommerce methods on TagManagerTracker
ebongzzang Oct 23, 2020
37f75a8
Test Release 0.11.0-alpha.1
ebongzzang Oct 26, 2020
eb2e216
Set user_id to GTagTracker
ebongzzang Oct 26, 2020
e767edd
Refactoring EcommerceTracker interface
ebongzzang Oct 26, 2020
248ed59
Fix method call with invalid aguments on beacon, gtag tracker
ebongzzang Oct 26, 2020
1ecc60c
Implement new ecommerce methods on tagmanager, beacon tracker
ebongzzang Oct 27, 2020
add8c1e
Release 0.11.0-alpha.3
ebongzzang Oct 28, 2020
81dd3a6
Capitalize first word on beacon events
ebongzzang Oct 28, 2020
3a75a01
Release 0.11.0-alpha.4
ebongzzang Oct 28, 2020
44091e8
Release 0.11.0-alpha.6
ebongzzang Oct 28, 2020
680ccbd
Reanme sendViewItemFromList to sendViewItemList
ebongzzang Oct 29, 2020
8776a9d
Add sendLogin event method
ebongzzang Oct 29, 2020
da5766d
Implement missing ecommerce methods
ebongzzang Oct 29, 2020
96fa11f
Remove unimplemented ecommerce methods
ebongzzang Oct 29, 2020
7484704
Release 0.11.0-alpha.7
ebongzzang Oct 29, 2020
80459a3
Remove redundant ecommerce methods
ebongzzang Oct 30, 2020
15d03e3
Update Item propeties
ebongzzang Oct 30, 2020
ba55306
Cleanup redundant method
ebongzzang Oct 30, 2020
927a792
Prevent init tracker twice in gtm tag
ebongzzang Oct 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ module.exports = {
'@ridi/eslint-config/typescript',
'@ridi/eslint-config/prettier',
],
overrides: [],
overrides: [
{
files: ['src/**/models/*.ts'],
rules: {
camelcase: 0,
},
},
],
rules: {
'no-console': 0,
semi: [2, 'always'],
Expand All @@ -18,7 +25,8 @@ module.exports = {
'import/no-unresolved': 0,
'import/extensions': 0,
'no-void': 1,
'no-shadow': 1,
'no-shadow': 0,
'@typescript-eslint/no-shadow': 0,
'@typescript-eslint/ban-ts-comment': 1,
'@typescript-eslint/no-unsafe-assignment': 1,
'@typescript-eslint/no-unsafe-call': 1,
Expand All @@ -32,6 +40,8 @@ module.exports = {
'import/prefer-default-export': 0,
'func-names': 0,
'@typescript-eslint/no-empty-function': 1,
'max-classes-per-file': ['error', 10],
'lines-around-comment': 0,
},
ignorePatterns: ['**/node_modules/**'],
ignorePatterns: ['**/node_modules/**', '**/dist/**'],
};
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ridi/event-tracker",
"version": "0.10.2",
"version": "0.11.0-alpha.7",
"description": "",
"main": "dist/cjs/index.js",
"typings": "dist/typings/index.d.ts",
Expand All @@ -12,7 +12,7 @@
"build": "npm run clean && npm run build:cjs && npm run build:umd",
"build:cjs": "tsc",
"build:umd": "webpack",
"deploy": "npm run build && npm publish -access public"
"deploy": "npm run build && npm publish -access public && npm install"
},
"pre-commit": [
"lint"
Expand All @@ -30,6 +30,7 @@
"devDependencies": {
"@ridi/eslint-config": "^5.1.0",
"@types/facebook-pixel": "0.0.19",
"@types/gtag.js": "0.0.3",
"@types/jest": "^24.0.12",
"@types/js-cookie": "^2.2.4",
"@types/url-parse": "^1.4.1",
Expand Down
30 changes: 12 additions & 18 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { DeviceType, MainTrackerOptions, Tracker } from '../index';
import {
DeviceType,
EventTrackerMethodNames,
MainTrackerOptions,
Tracker,
} from '../index';
import {
BeaconTracker,
GATracker,
Expand All @@ -7,7 +12,7 @@ import {
TagManagerTracker,
TwitterTracker,
} from '../trackers';
import { BaseTracker, EventTracker } from '../trackers/base';
import { BaseTracker } from '../trackers/base';

const ALL_TRACKERS = [
BeaconTracker,
Expand Down Expand Up @@ -95,7 +100,7 @@ class TestableTracker extends Tracker {

public mocking(
trackers: Array<new (...args: any[]) => BaseTracker>,
methodName: keyof EventTracker,
methodName: EventTrackerMethodNames,
mockImpl: () => void = () => true,
) {
const mockingTargetTrackers = this.getTrackerInstances(...trackers);
Expand All @@ -106,7 +111,7 @@ class TestableTracker extends Tracker {

public mockingAll(
trackers: Array<new (...args: any[]) => BaseTracker>,
methodNames: Array<keyof EventTracker>,
methodNames: Array<EventTrackerMethodNames>,
mockImpl: () => void = () => true,
) {
return methodNames.map(m => this.mocking(trackers, m, mockImpl));
Expand Down Expand Up @@ -134,13 +139,12 @@ it('BeaconTracker sends PageView event with serviceProps', async () => {
const sendBeaconMock = jest.fn();

// @ts-ignore

BeaconTracker.prototype.sendBeacon = sendBeaconMock;
t.sendPageView(href, referrer);

jest.runOnlyPendingTimers();
expect(sendBeaconMock).toHaveBeenCalledWith(
'pageView',
'PageView',
dummpyPageMeta,
{ prop1: 'value1', prop2: 'value2' },
expect.any(Date),
Expand Down Expand Up @@ -222,7 +226,6 @@ it('GATracker should send pageview event', async () => {
await t.initialize();

// @ts-ignore

window.ga = jest.fn();
t.sendPageView(href, referrer);

Expand All @@ -234,7 +237,7 @@ it('GATracker should send pageview event', async () => {
);
});

it('Test TwitterTracker', async () => {
it.skip('Test TwitterTracker', async () => {
const t = new TestableTracker({
twitterOptions: {
mainPid: 'mainPid',
Expand All @@ -246,9 +249,7 @@ it('Test TwitterTracker', async () => {

t.mockingAll(ALL_TRACKERS.excludes(TwitterTracker), [
'sendPageView',
'sendImpression',
'sendSignUp',
'sendStartSubscription',
]);

const trackPidMock = jest.fn();
Expand All @@ -257,28 +258,21 @@ it('Test TwitterTracker', async () => {
const twitterTracker = t.getTrackerInstance(TwitterTracker);

// @ts-ignore

twitterTracker.twttr = { conversion: {} };

// @ts-ignore

twitterTracker.twttr.conversion.trackPid = trackPidMock;

// @ts-ignore

twitterTracker.twq = twqMock;

await t.initialize();

/* Need to disable flush throttling when sending event multiple times in one test cases */
// @ts-ignore

t.throttledFlush = t.flush.bind(t);

t.sendPageView('href');
t.sendImpression();
t.sendSignUp();
t.sendStartSubscription();
t.sendSignUp('method');

jest.runOnlyPendingTimers();

Expand Down
9 changes: 9 additions & 0 deletions src/ecommerce/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum Currency {
KRW = 'KRW',
USD = 'USD',
}

export enum ServiceType {
RIDIBOOKS = 'ridibooks',
RIDISELECT = 'ridiselect',
}
2 changes: 2 additions & 0 deletions src/ecommerce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './interface';
export * from './models';
28 changes: 28 additions & 0 deletions src/ecommerce/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PurchaseInfo } from './models/transaction';
import { Item, Promotion } from './models';

export interface EcommerceTracker {
sendAddPaymentInfo(
paymentType: string,
purchaseInfo: PurchaseInfo,
ts?: Date,
): void;

sendBeginCheckout(purchaseInfo: PurchaseInfo, ts?: Date): void;

sendPurchase(
transactionId: string,
purchaseInfo: PurchaseInfo,
ts?: Date,
): void;

sendViewItem(items: Item[], ts?: Date): void;

sendAddToPreference(items: Item[], ts?: Date): void;

sendAddToNewBookNotification(items: Item[], ts?: Date): void;

sendViewContent(item: Item, ts?: Date): void;

sendViewItemList(items: Item[], ts?: Date): void;
}
2 changes: 2 additions & 0 deletions src/ecommerce/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './item';
export * from './promotion';
23 changes: 23 additions & 0 deletions src/ecommerce/models/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Currency, ServiceType } from '../constants';
import { Promotion } from './promotion';

export interface Item extends Partial<Promotion> {
readonly item_id: string;
readonly item_name: string;
readonly item_repr_id?: string;
readonly item_repr_name?: string;
readonly service_type: ServiceType;
readonly author_id?: number;
readonly author: string;
readonly item_provider_id: number;
readonly item_provider_name: string;
readonly item_category: string;
readonly item_genre?: string;
readonly coupon?: string;
readonly discount?: number;
readonly price?: number;
readonly currency?: Currency;
readonly index?: number;
readonly item_list_id?: string;
readonly item_list_name?: string;
}
6 changes: 6 additions & 0 deletions src/ecommerce/models/promotion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Promotion {
readonly promotion_id: string;
readonly promotion_name: string;
readonly creative_name?: string;
readonly creative_slot?: number;
}
12 changes: 12 additions & 0 deletions src/ecommerce/models/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Currency } from '../constants';
import { Item } from './item';

export interface PurchaseInfo {
readonly coupon_name: string;
readonly coupon: number;
readonly cash: number;
readonly point: number;
readonly currency: Currency;
readonly value: number;
readonly items: Item[];
}
Loading