Skip to content

Commit cd7a674

Browse files
committed
Added Typescript support
- added typescript dependency and tsconfig.json - updated .babelrc to compile typescript files - renamed src/index.js to src/index.ts - added types to all paramaters - when building, emits a type declaration - tests now build first and uses built file to run Closes #26.
1 parent 716888a commit cd7a674

File tree

8 files changed

+1307
-139
lines changed

8 files changed

+1307
-139
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["@babel/env"]
2+
"presets": ["@babel/env", "@babel/preset-typescript"]
33
}

lib/index.d.ts

+311
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
interface IEvent {
2+
evLabel?: string;
3+
evValue?: string;
4+
clientID?: string;
5+
}
6+
interface ITransaction {
7+
trnAffil?: string;
8+
trnRev?: string;
9+
trnShip?: number;
10+
trnTax?: number;
11+
currCode?: string;
12+
}
13+
interface IRefund {
14+
prdID?: string;
15+
prdQty?: string;
16+
}
17+
interface IPurchase {
18+
trnAffil?: string;
19+
trnRev?: string;
20+
trnTax?: number;
21+
trnShip?: number;
22+
trnCoupon?: string;
23+
prdID?: string;
24+
prdName?: string;
25+
prdCtg?: string;
26+
prdBrand?: string;
27+
prdVar?: string;
28+
prdPos?: string;
29+
}
30+
interface ICheckout {
31+
prdID?: string;
32+
prdName?: string;
33+
prdCtg?: string;
34+
prdBrand?: string;
35+
prdVar?: string;
36+
prdPrice?: number;
37+
prdQty?: number;
38+
}
39+
interface IPromoImp {
40+
promoID?: string;
41+
promoName?: string;
42+
promoCrt?: string;
43+
promoPos?: string;
44+
}
45+
interface IPromoCk extends IPromoImp {
46+
evLabel?: string;
47+
}
48+
interface IItem {
49+
itemPrice?: number;
50+
itemQty?: string;
51+
itemSku?: string;
52+
itemVariation?: string;
53+
currCode?: string;
54+
}
55+
interface ITimingTrk {
56+
timingLbl?: string;
57+
dns?: number;
58+
pageDownTime?: number;
59+
redirTime?: number;
60+
tcpConnTime?: number;
61+
serverResTime?: number;
62+
}
63+
declare class Analytics {
64+
private globalDebug;
65+
private globalUserAgent;
66+
private globalBaseURL;
67+
private globalDebugURL;
68+
private globalCollectURL;
69+
private globalBatchURL;
70+
private globalTrackingID;
71+
private globalVersion;
72+
private customParams;
73+
/**
74+
* Constructor
75+
*
76+
* @param {string} trackingID
77+
* @param {Object} param1
78+
*/
79+
constructor(trackingID: string, { userAgent, debug, version }?: {
80+
userAgent?: string | undefined;
81+
debug?: boolean | undefined;
82+
version?: number | undefined;
83+
});
84+
/**
85+
* Adds custom parameters to requests
86+
* if value is null, then parameter will be removed
87+
*
88+
* @param {string} key Parameter name
89+
* @param {string} value Parameter value
90+
*/
91+
set(key: string, value: string): void;
92+
/**
93+
* Send a "pageview" request
94+
*
95+
* @param {string} url Url of the page
96+
* @param {string} title Title of the page
97+
* @param {string} hostname Document hostname
98+
* @param {string} clientID uuidV4
99+
* @param {string} sessDuration A string to force start or end a session
100+
*
101+
* @return {Promise}
102+
*/
103+
pageview(hostname: string, url: string, title: string, clientID?: string, sessDuration?: string): Promise<Error | {
104+
clientID: string | number;
105+
}>;
106+
/**
107+
* Send a "event" request
108+
*
109+
* @param {string} evCategory Event category
110+
* @param {string} evAction Event action
111+
* @param {string} clientID uuidV4
112+
* @param {string} evLabel Event label
113+
* @param {string} evValue Event description
114+
*
115+
* @return {Promise}
116+
*/
117+
event(evCategory: string, evAction: string, { evLabel, evValue, clientID }?: IEvent): Promise<Error | {
118+
clientID: string | number;
119+
}>;
120+
/**
121+
* Send a "screenview" request
122+
*
123+
* @param {string} appName App name
124+
* @param {string} appVer App version
125+
* @param {string} appID App Id
126+
* @param {string} appInstallerID App Installer Id
127+
* @param {string} screenName Screen name / Content description
128+
* @param {string} clientID uuidV4
129+
*
130+
* @return {Promise}
131+
*/
132+
screen(appName: string, appVer: string, appID: string, appInstallerID: string, screenName: string, clientID?: string): Promise<Error | {
133+
clientID: string | number;
134+
}>;
135+
/**
136+
* Send a "transaction" request
137+
*
138+
* @param {string} trnID Transaction ID
139+
* @param {string} trnAffil Transaction affiliation
140+
* @param {string} trnRev Transaction Revenue
141+
* @param {Number} trnShip Transaction shipping
142+
* @param {Number} trnTax Transaction tax
143+
* @param {string} currCode Currency code
144+
* @param {string} clientID uuidV4
145+
*
146+
* @return {Promise}
147+
*/
148+
transaction(trnID: string, { trnAffil, trnRev, trnShip, trnTax, currCode }?: ITransaction, clientID?: string): Promise<Error | {
149+
clientID: string | number;
150+
}>;
151+
/**
152+
* Send a "social" request
153+
*
154+
* @param {string} socialAction Social Action
155+
* @param {string} socialNetwork Social Network
156+
* @param {string} socialTarget Social Target
157+
* @param {string} clientID uuidV4
158+
*
159+
* @return {Promise}
160+
*/
161+
social(socialAction: string, socialNetwork: string, socialTarget: string, clientID?: string): Promise<Error | {
162+
clientID: string | number;
163+
}>;
164+
/**
165+
* Send a "exception" request
166+
*
167+
* @param {string} exDesc Exception description
168+
* @param {Number} exFatal Exception is fatal?
169+
* @param {string} clientID uuidV4
170+
*
171+
* @return {Promise}
172+
*/
173+
exception(exDesc: string, exFatal: number, clientID?: string): Promise<Error | {
174+
clientID: string | number;
175+
}>;
176+
/**
177+
* Send a "refund" request
178+
*
179+
* @param {string} trnID Transaction ID
180+
* @param {string} evCategory Event category
181+
* @param {string} evAction Event action
182+
* @param {Number} nonInteraction Non-interaction parameter
183+
* @param {string} prdID Product ID
184+
* @param {Number} prdQty Product quantity
185+
* @param {string} clientID uuidV4
186+
*
187+
* @returns {Promise}
188+
*/
189+
refund(trnID: string, evCategory?: string, evAction?: string, nonInteraction?: number, { prdID, prdQty }?: IRefund, clientID?: string): Promise<Error | {
190+
clientID: string | number;
191+
}>;
192+
/**
193+
* Send a "purchase" request
194+
* @param {string} hostname Document hostname
195+
* @param {string} url Url of the page
196+
* @param {string} title Title of the page
197+
* @param {string} transactionID Transaction ID
198+
* @param {string} trnAffil Transaction affiliation
199+
* @param {string} trnRev Transaction Revenue
200+
* @param {Number} trnTax Transaction tax
201+
* @param {Number} trnShip Transaction shipping
202+
* @param {string} trnCoupon Transaction coupon
203+
* @param {string} prdID Product ID
204+
* @param {string} prdName Product name
205+
* @param {string} prdCtg Product category
206+
* @param {string} prdBrand Product brand
207+
* @param {string} prdVar Product variant
208+
* @param {string} prdPos Product position
209+
* @param {string} clientID uuidV4
210+
* @return {Promise}
211+
*/
212+
purchase(hostname: string, url: string, title: string, transactionID: string, { trnAffil, trnRev, trnTax, trnShip, trnCoupon, prdID, prdName, prdCtg, prdBrand, prdVar, prdPos, }?: IPurchase, clientID?: string): Promise<Error | {
213+
clientID: string | number;
214+
}>;
215+
/**
216+
* Send a "checkout" request
217+
* @param {string} hostname Document hostname
218+
* @param {string} url Url of the page
219+
* @param {string} title Title of the page
220+
* @param {string} checkoutStep Checkout step
221+
* @param {string} checkoutOpt Checkout step option
222+
* @param {string} prdID Product ID
223+
* @param {string} prdName Product name
224+
* @param {string} prdCtg Product category
225+
* @param {string} prdBrand Product brand
226+
* @param {string} prdVar Product variant
227+
* @param {Number} prdPrice Product price
228+
* @param {Number} prdQty Product category
229+
* @param {string} clientID uuidV4
230+
* @return {Promise}
231+
*/
232+
checkout(hostname: string, url: string, title: string, checkoutStep: string, checkoutOpt: string, { prdID, prdName, prdCtg, prdBrand, prdVar, prdPrice, prdQty, }?: ICheckout, clientID?: string): Promise<Error | {
233+
clientID: string | number;
234+
}>;
235+
/**
236+
* Send a "checkout_option" request
237+
* @param {string} evCategory Event category
238+
* @param {string} evAction Event action
239+
* @param {string} checkoutStep Checkout step
240+
* @param {string} checkoutOpt Checkout step option
241+
* @param {string} clientID uuidV4
242+
* @return {Promise}
243+
*/
244+
checkoutOpt(evCategory: string, evAction: string, checkoutStep?: string, checkoutOpt?: string, clientID?: string): Promise<Error | {
245+
clientID: string | number;
246+
}>;
247+
/**
248+
*
249+
* @param {*} hostname
250+
* @param {*} url
251+
* @param {*} title
252+
* @param {*} param3
253+
* @param {*} clientID
254+
*/
255+
promoImp(hostname: string, url: string, title: string, { promoID, promoName, promoCrt, promoPos }?: IPromoImp, clientID?: string): Promise<Error | {
256+
clientID: string | number;
257+
}>;
258+
/**
259+
*
260+
* @param {*} evCategory
261+
* @param {*} evAction
262+
* @param {*} param2
263+
* @param {*} clientID
264+
*/
265+
promoCk(evCategory: string, evAction: string, { evLabel, promoID, promoName, promoCrt, promoPos }?: IPromoCk, clientID?: string): Promise<Error | {
266+
clientID: string | number;
267+
}>;
268+
/**
269+
* Send a "item" request
270+
* @param {string} trnID Transaction ID
271+
* @param {string} itemName Item name
272+
* @param {Number} itemPrice Item price
273+
* @param {string} itemQty Item quantity
274+
* @param {string} itemSku Item SKU
275+
* @param {string} itemVariation Item variation / category
276+
* @param {string} currCode Currency code
277+
* @param {string} clientID uuidV4
278+
* @return {Promise}
279+
*/
280+
item(trnID: string, itemName: string, { itemPrice, itemQty, itemSku, itemVariation, currCode }?: IItem, clientID?: string): Promise<Error | {
281+
clientID: string | number;
282+
}>;
283+
/**
284+
* Send a "timing tracking" request
285+
* @param {string} timingCtg Timing category
286+
* @param {string} timingVar Timing variable
287+
* @param {Number} timingTime Timing time
288+
* @param {string} timingLbl Timing label
289+
* @param {Number} dns DNS load time
290+
* @param {Number} pageDownTime Page download time
291+
* @param {Number} redirTime Redirect time
292+
* @param {Number} tcpConnTime TCP connect time
293+
* @param {Number} serverResTime Server response time
294+
* @param {string} clientID uuidV4
295+
* @return {Promise}
296+
*/
297+
timingTrk(timingCtg: string, timingVar: string, timingTime: number, { timingLbl, dns, pageDownTime, redirTime, tcpConnTime, serverResTime, }?: ITimingTrk, clientID?: string): Promise<Error | {
298+
clientID: string | number;
299+
}>;
300+
/**
301+
* Send a request to google-analytics
302+
*
303+
* @param {string} hitType Hit type
304+
* @param {string} clientID Unique identifier (uuidV4)
305+
* @param {Object} params Options
306+
*
307+
* @return {Promise}
308+
*/
309+
private send;
310+
}
311+
export default Analytics;

0 commit comments

Comments
 (0)