Skip to content

Commit 8087c1e

Browse files
authored
Merge pull request #6 from ridi/dev/0.1/miscs
Add EventClient.setUId, Remove paymentType on sendAddPaymentInfo
2 parents 6bb5a6c + a59ad15 commit 8087c1e

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ridi/event-client",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Ridibooks event tracking client",
55
"main": "dist/cjs/index.js",
66
"typings": "dist/typings/index.d.ts",

src/eventClient.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare global {
1818
}
1919

2020
export class EventClient {
21-
private tagCalled = false;
21+
private readonly tagCalled: boolean = false;
2222

2323
constructor(private options: ClientOptions) {
2424
if (this.options.autoPageView === undefined) {
@@ -32,12 +32,6 @@ export class EventClient {
3232
this.pushDataLayer({ event: 'Init', ...options });
3333
}
3434

35-
public setUId(uId: number): void {
36-
this.options.uId = uId;
37-
38-
this.pushDataLayer(this.options);
39-
}
40-
4135
private get dataLayer() {
4236
if (!this.tagCalled) {
4337
window.dataLayer = window.dataLayer || [];
@@ -46,11 +40,10 @@ export class EventClient {
4640
return window.dataLayer;
4741
}
4842

49-
private pushDataLayer(data: Record<string, any>): void {
50-
if (!this.tagCalled) {
51-
console.warn('[@ridi/ridi-event-client] GTM is not initialized.');
52-
}
53-
this.dataLayer.push(data);
43+
public setUId(uId: number): void {
44+
this.options.uId = uId;
45+
46+
this.pushDataLayer({ event: 'UIdChanged', ...this.options });
5447
}
5548

5649
public sendEvent(
@@ -118,12 +111,8 @@ export class EventClient {
118111
this.sendEvent('BeginCheckout', { items }, ts);
119112
}
120113

121-
public sendAddPaymentInfo(
122-
paymentType: string,
123-
purchaseInfo: PurchaseInfo,
124-
ts?: Date,
125-
): void {
126-
this.sendEvent('AddPaymentInfo', { paymentType, ...purchaseInfo }, ts);
114+
public sendAddPaymentInfo(purchaseInfo: PurchaseInfo, ts?: Date): void {
115+
this.sendEvent('AddPaymentInfo', { ...purchaseInfo }, ts);
127116
}
128117

129118
public sendEnrollPreference(items: Item[], ts?: Date): void {
@@ -157,4 +146,11 @@ export class EventClient {
157146
): void {
158147
this.sendEvent('Purchase', { transactionId, ...purchaseInfo }, ts);
159148
}
149+
150+
private pushDataLayer(data: Record<string, any>): void {
151+
if (!this.tagCalled) {
152+
console.warn('[@ridi/ridi-event-client] GTM is not initialized.');
153+
}
154+
this.dataLayer.push(data);
155+
}
160156
}

src/models/item.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export interface Item {
88
readonly item_episode_id?: string;
99
readonly item_category: number;
1010
readonly item_genre?: string;
11+
/**
12+
* Original price of item that does not apply any discount
13+
* @remarks price should be provided when event is AddPaymentInfo, Purchase
14+
* @see {@link EventClient#sendPurchase}, {@link EventClient#sendAddPaymentInfo}
15+
*/
1116
readonly price?: number;
1217
readonly quantity: number;
1318
}

0 commit comments

Comments
 (0)