@fuul/sdk 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants.js +2 -2
- package/lib/cjs/index.js +26 -20
- package/lib/cjs/infrastructure/campaigns/campaignsService.js +14 -8
- package/lib/cjs/types/constants.d.ts +1 -1
- package/lib/cjs/types/constants.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +4 -3
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts +1 -1
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -1
- package/lib/cjs/types/types/types.d.ts +1 -1
- package/lib/cjs/types/utils/localStorage.d.ts +1 -1
- package/lib/cjs/types/utils/localStorage.d.ts.map +1 -1
- package/lib/cjs/utils/localStorage.js +3 -3
- package/lib/esm/constants.js +1 -1
- package/lib/esm/index.mjs +28 -22
- package/lib/esm/infrastructure/campaigns/campaignsService.js +14 -8
- package/lib/esm/types/constants.d.ts +1 -1
- package/lib/esm/types/constants.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +4 -3
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts +1 -1
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -1
- package/lib/esm/types/types/types.d.ts +1 -1
- package/lib/esm/types/utils/localStorage.d.ts +1 -1
- package/lib/esm/types/utils/localStorage.d.ts.map +1 -1
- package/lib/esm/utils/localStorage.js +2 -2
- package/package.json +1 -2
package/lib/cjs/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SENT_EVENT_ID_KEY = exports.REFERRER_ID_KEY = exports.
|
|
3
|
+
exports.SENT_EVENT_ID_KEY = exports.REFERRER_ID_KEY = exports.PROJECT_ID_KEY = exports.TRACKING_ID_KEY = exports.SESSION_ID_KEY = void 0;
|
|
4
4
|
exports.SESSION_ID_KEY = "fuul.session_id";
|
|
5
5
|
exports.TRACKING_ID_KEY = "fuul.tracking_id";
|
|
6
|
-
exports.
|
|
6
|
+
exports.PROJECT_ID_KEY = "fuul.project_id";
|
|
7
7
|
exports.REFERRER_ID_KEY = "fuul.referrer_id";
|
|
8
8
|
exports.SENT_EVENT_ID_KEY = "fuul.sent";
|
package/lib/cjs/index.js
CHANGED
|
@@ -46,11 +46,11 @@ const saveSessionId = () => {
|
|
|
46
46
|
localStorage.setItem(constants_js_1.SESSION_ID_KEY, generateRandomId());
|
|
47
47
|
};
|
|
48
48
|
const saveTrackingId = () => {
|
|
49
|
-
var _a
|
|
49
|
+
var _a;
|
|
50
50
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
51
51
|
return;
|
|
52
52
|
const queryParams = new URLSearchParams(window.location.search);
|
|
53
|
-
if (!queryParams.has("
|
|
53
|
+
if (!queryParams.has("p") ||
|
|
54
54
|
!queryParams.has("origin") ||
|
|
55
55
|
!queryParams.has("r"))
|
|
56
56
|
return;
|
|
@@ -60,15 +60,14 @@ const saveTrackingId = () => {
|
|
|
60
60
|
if (!(0, localStorage_js_1.getTrackingId)()) {
|
|
61
61
|
localStorage.setItem(constants_js_1.TRACKING_ID_KEY, generateRandomId());
|
|
62
62
|
}
|
|
63
|
-
localStorage.setItem(constants_js_1.
|
|
64
|
-
localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
|
|
63
|
+
localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_a = queryParams.get("r")) !== null && _a !== void 0 ? _a : "");
|
|
65
64
|
};
|
|
66
|
-
const buildTrackingLinkQueryParams = (r,
|
|
67
|
-
return `
|
|
65
|
+
const buildTrackingLinkQueryParams = (r, p) => {
|
|
66
|
+
return `p=${p}&origin=fuul&r=${r}`;
|
|
68
67
|
};
|
|
69
68
|
class Fuul {
|
|
70
69
|
constructor(apiKey) {
|
|
71
|
-
this.BASE_API_URL = "
|
|
70
|
+
this.BASE_API_URL = "http://localhost:14000/api/v1/";
|
|
72
71
|
this.apiKey = apiKey;
|
|
73
72
|
this.checkApiKey();
|
|
74
73
|
saveSessionId();
|
|
@@ -80,10 +79,17 @@ class Fuul {
|
|
|
80
79
|
});
|
|
81
80
|
this.campaignsService = new campaignsService_js_1.CampaignsService(this.httpClient);
|
|
82
81
|
this.init();
|
|
82
|
+
this.events();
|
|
83
83
|
}
|
|
84
84
|
init() {
|
|
85
85
|
globalThis.Fuul = this;
|
|
86
86
|
}
|
|
87
|
+
events() {
|
|
88
|
+
// window.addEventListener("DOMContentLoaded", () => {
|
|
89
|
+
// this.sendEvent("pageview");
|
|
90
|
+
// });
|
|
91
|
+
console.log("we should send pageview event here");
|
|
92
|
+
}
|
|
87
93
|
checkApiKey() {
|
|
88
94
|
if (!this.apiKey) {
|
|
89
95
|
throw new Error("Fuul API key is required");
|
|
@@ -109,7 +115,6 @@ class Fuul {
|
|
|
109
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
116
|
const session_id = (0, localStorage_js_1.getSessionId)();
|
|
111
117
|
const tracking_id = (0, localStorage_js_1.getTrackingId)();
|
|
112
|
-
const campaign_id = (0, localStorage_js_1.getCampaignId)();
|
|
113
118
|
const referrer_id = (0, localStorage_js_1.getReferrerId)();
|
|
114
119
|
if (!tracking_id)
|
|
115
120
|
return;
|
|
@@ -125,25 +130,26 @@ class Fuul {
|
|
|
125
130
|
};
|
|
126
131
|
}
|
|
127
132
|
else {
|
|
128
|
-
if (!
|
|
133
|
+
if (!referrer_id)
|
|
129
134
|
return;
|
|
130
|
-
params = Object.assign(Object.assign({}, params), { referrer_id
|
|
131
|
-
campaign_id });
|
|
135
|
+
params = Object.assign(Object.assign({}, params), { referrer_id });
|
|
132
136
|
reqBody = {
|
|
133
137
|
name,
|
|
134
138
|
session_id,
|
|
135
|
-
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id,
|
|
136
|
-
tracking_id }),
|
|
139
|
+
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
142
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
140
143
|
return;
|
|
141
144
|
try {
|
|
142
|
-
|
|
145
|
+
const PATH = (args === null || args === void 0 ? void 0 : args.project_id)
|
|
146
|
+
? `events?project_id=${args.project_id}`
|
|
147
|
+
: "events";
|
|
148
|
+
yield this.httpClient.post(PATH, reqBody);
|
|
143
149
|
saveSentEvent(name, params);
|
|
144
150
|
}
|
|
145
151
|
catch (error) {
|
|
146
|
-
|
|
152
|
+
return error;
|
|
147
153
|
}
|
|
148
154
|
});
|
|
149
155
|
}
|
|
@@ -155,16 +161,16 @@ class Fuul {
|
|
|
155
161
|
/**
|
|
156
162
|
* Generates a tracking link for a referrer
|
|
157
163
|
* @param {string} address referrer address
|
|
158
|
-
* @param {string}
|
|
164
|
+
* @param {string} pid project id you want to refer the user
|
|
159
165
|
* @param {string} baseUrl base url of your app
|
|
160
166
|
* @returns {string} tracking link
|
|
161
167
|
*/
|
|
162
|
-
generateTrackingLink({ address,
|
|
163
|
-
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address,
|
|
168
|
+
generateTrackingLink({ address, pid, baseUrl, }) {
|
|
169
|
+
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, pid)}`;
|
|
164
170
|
}
|
|
165
|
-
|
|
171
|
+
getAllCampaigns(args) {
|
|
166
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
return
|
|
173
|
+
return this.campaignsService.getAllCampaignsByProjectId(args);
|
|
168
174
|
});
|
|
169
175
|
}
|
|
170
176
|
}
|
|
@@ -10,19 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CampaignsService = void 0;
|
|
13
|
+
const buildQueryParams = (args) => {
|
|
14
|
+
let queryParams = "";
|
|
15
|
+
Object.keys(args).forEach((key) => {
|
|
16
|
+
queryParams =
|
|
17
|
+
queryParams === ""
|
|
18
|
+
? queryParams + `${key}=${args[key]}`
|
|
19
|
+
: queryParams + "&" + `${key}=${args[key]}`;
|
|
20
|
+
});
|
|
21
|
+
return queryParams;
|
|
22
|
+
};
|
|
13
23
|
class CampaignsService {
|
|
14
24
|
constructor(httpClient) {
|
|
15
25
|
this.httpClient = httpClient;
|
|
16
26
|
}
|
|
17
|
-
|
|
27
|
+
getAllCampaignsByProjectId(args) {
|
|
18
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return error;
|
|
25
|
-
}
|
|
29
|
+
const PATH = args ? `campaigns?${buildQueryParams(args)}` : `campaigns`;
|
|
30
|
+
const { data } = yield this.httpClient.get(PATH);
|
|
31
|
+
return data;
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export declare const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export declare const SENT_EVENT_ID_KEY = "fuul.sent";
|
|
6
6
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Fuul {
|
|
|
7
7
|
private campaignsService;
|
|
8
8
|
constructor(apiKey: string);
|
|
9
9
|
init(): void;
|
|
10
|
+
events(): void;
|
|
10
11
|
checkApiKey(): void;
|
|
11
12
|
/**
|
|
12
13
|
* @param {EventType} name Event name.
|
|
@@ -29,12 +30,12 @@ export declare class Fuul {
|
|
|
29
30
|
/**
|
|
30
31
|
* Generates a tracking link for a referrer
|
|
31
32
|
* @param {string} address referrer address
|
|
32
|
-
* @param {string}
|
|
33
|
+
* @param {string} pid project id you want to refer the user
|
|
33
34
|
* @param {string} baseUrl base url of your app
|
|
34
35
|
* @returns {string} tracking link
|
|
35
36
|
*/
|
|
36
|
-
generateTrackingLink({ address,
|
|
37
|
-
|
|
37
|
+
generateTrackingLink({ address, pid, baseUrl, }: IGenerateTrackingLink): string;
|
|
38
|
+
getAllCampaigns(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
38
39
|
}
|
|
39
40
|
declare const _default: {
|
|
40
41
|
Fuul: typeof Fuul;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA0EjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4C;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAmB1B,IAAI;IAIJ,MAAM;IAON,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAuDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAG7E;;;;AAMD,wBAEE"}
|
|
@@ -3,6 +3,6 @@ import { CampaignDTO } from "./dtos.js";
|
|
|
3
3
|
export declare class CampaignsService {
|
|
4
4
|
private httpClient;
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
6
|
-
|
|
6
|
+
getAllCampaignsByProjectId(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAexC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,0BAA0B,CAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,WAAW,EAAE,CAAC;CAM1B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getSessionId: () => string | null;
|
|
2
2
|
export declare const getTrackingId: () => string | null;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getProjectId: () => string | null;
|
|
4
4
|
export declare const getReferrerId: () => string | null;
|
|
5
5
|
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReferrerId = exports.
|
|
3
|
+
exports.getReferrerId = exports.getProjectId = exports.getTrackingId = exports.getSessionId = void 0;
|
|
4
4
|
const constants_js_1 = require("../constants.js");
|
|
5
5
|
const getSessionId = () => localStorage.getItem(constants_js_1.SESSION_ID_KEY);
|
|
6
6
|
exports.getSessionId = getSessionId;
|
|
7
7
|
const getTrackingId = () => localStorage.getItem(constants_js_1.TRACKING_ID_KEY);
|
|
8
8
|
exports.getTrackingId = getTrackingId;
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
9
|
+
const getProjectId = () => localStorage.getItem(constants_js_1.PROJECT_ID_KEY);
|
|
10
|
+
exports.getProjectId = getProjectId;
|
|
11
11
|
const getReferrerId = () => localStorage.getItem(constants_js_1.REFERRER_ID_KEY);
|
|
12
12
|
exports.getReferrerId = getReferrerId;
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export const
|
|
3
|
+
export const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export const SENT_EVENT_ID_KEY = "fuul.sent";
|
package/lib/esm/index.mjs
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
11
|
import { datesAreOnSameDay } from "./utils/date.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { getReferrerId, getSessionId, getTrackingId, } from "./utils/localStorage.js";
|
|
13
|
+
import { REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "./constants.js";
|
|
14
14
|
import { HttpClient } from "./infrastructure/http/HttpClient.js";
|
|
15
15
|
import { CampaignsService } from "./infrastructure/campaigns/campaignsService.js";
|
|
16
16
|
const saveSentEvent = (eventName, params) => {
|
|
@@ -43,11 +43,11 @@ const saveSessionId = () => {
|
|
|
43
43
|
localStorage.setItem(SESSION_ID_KEY, generateRandomId());
|
|
44
44
|
};
|
|
45
45
|
const saveTrackingId = () => {
|
|
46
|
-
var _a
|
|
46
|
+
var _a;
|
|
47
47
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
48
48
|
return;
|
|
49
49
|
const queryParams = new URLSearchParams(window.location.search);
|
|
50
|
-
if (!queryParams.has("
|
|
50
|
+
if (!queryParams.has("p") ||
|
|
51
51
|
!queryParams.has("origin") ||
|
|
52
52
|
!queryParams.has("r"))
|
|
53
53
|
return;
|
|
@@ -57,15 +57,14 @@ const saveTrackingId = () => {
|
|
|
57
57
|
if (!getTrackingId()) {
|
|
58
58
|
localStorage.setItem(TRACKING_ID_KEY, generateRandomId());
|
|
59
59
|
}
|
|
60
|
-
localStorage.setItem(
|
|
61
|
-
localStorage.setItem(REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
|
|
60
|
+
localStorage.setItem(REFERRER_ID_KEY, (_a = queryParams.get("r")) !== null && _a !== void 0 ? _a : "");
|
|
62
61
|
};
|
|
63
|
-
const buildTrackingLinkQueryParams = (r,
|
|
64
|
-
return `
|
|
62
|
+
const buildTrackingLinkQueryParams = (r, p) => {
|
|
63
|
+
return `p=${p}&origin=fuul&r=${r}`;
|
|
65
64
|
};
|
|
66
65
|
export class Fuul {
|
|
67
66
|
constructor(apiKey) {
|
|
68
|
-
this.BASE_API_URL = "
|
|
67
|
+
this.BASE_API_URL = "http://localhost:14000/api/v1/";
|
|
69
68
|
this.apiKey = apiKey;
|
|
70
69
|
this.checkApiKey();
|
|
71
70
|
saveSessionId();
|
|
@@ -77,10 +76,17 @@ export class Fuul {
|
|
|
77
76
|
});
|
|
78
77
|
this.campaignsService = new CampaignsService(this.httpClient);
|
|
79
78
|
this.init();
|
|
79
|
+
this.events();
|
|
80
80
|
}
|
|
81
81
|
init() {
|
|
82
82
|
globalThis.Fuul = this;
|
|
83
83
|
}
|
|
84
|
+
events() {
|
|
85
|
+
// window.addEventListener("DOMContentLoaded", () => {
|
|
86
|
+
// this.sendEvent("pageview");
|
|
87
|
+
// });
|
|
88
|
+
console.log("we should send pageview event here");
|
|
89
|
+
}
|
|
84
90
|
checkApiKey() {
|
|
85
91
|
if (!this.apiKey) {
|
|
86
92
|
throw new Error("Fuul API key is required");
|
|
@@ -106,7 +112,6 @@ export class Fuul {
|
|
|
106
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
113
|
const session_id = getSessionId();
|
|
108
114
|
const tracking_id = getTrackingId();
|
|
109
|
-
const campaign_id = getCampaignId();
|
|
110
115
|
const referrer_id = getReferrerId();
|
|
111
116
|
if (!tracking_id)
|
|
112
117
|
return;
|
|
@@ -122,25 +127,26 @@ export class Fuul {
|
|
|
122
127
|
};
|
|
123
128
|
}
|
|
124
129
|
else {
|
|
125
|
-
if (!
|
|
130
|
+
if (!referrer_id)
|
|
126
131
|
return;
|
|
127
|
-
params = Object.assign(Object.assign({}, params), { referrer_id
|
|
128
|
-
campaign_id });
|
|
132
|
+
params = Object.assign(Object.assign({}, params), { referrer_id });
|
|
129
133
|
reqBody = {
|
|
130
134
|
name,
|
|
131
135
|
session_id,
|
|
132
|
-
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id,
|
|
133
|
-
tracking_id }),
|
|
136
|
+
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
134
137
|
};
|
|
135
138
|
}
|
|
136
139
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
137
140
|
return;
|
|
138
141
|
try {
|
|
139
|
-
|
|
142
|
+
const PATH = (args === null || args === void 0 ? void 0 : args.project_id)
|
|
143
|
+
? `events?project_id=${args.project_id}`
|
|
144
|
+
: "events";
|
|
145
|
+
yield this.httpClient.post(PATH, reqBody);
|
|
140
146
|
saveSentEvent(name, params);
|
|
141
147
|
}
|
|
142
148
|
catch (error) {
|
|
143
|
-
|
|
149
|
+
return error;
|
|
144
150
|
}
|
|
145
151
|
});
|
|
146
152
|
}
|
|
@@ -152,16 +158,16 @@ export class Fuul {
|
|
|
152
158
|
/**
|
|
153
159
|
* Generates a tracking link for a referrer
|
|
154
160
|
* @param {string} address referrer address
|
|
155
|
-
* @param {string}
|
|
161
|
+
* @param {string} pid project id you want to refer the user
|
|
156
162
|
* @param {string} baseUrl base url of your app
|
|
157
163
|
* @returns {string} tracking link
|
|
158
164
|
*/
|
|
159
|
-
generateTrackingLink({ address,
|
|
160
|
-
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address,
|
|
165
|
+
generateTrackingLink({ address, pid, baseUrl, }) {
|
|
166
|
+
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, pid)}`;
|
|
161
167
|
}
|
|
162
|
-
|
|
168
|
+
getAllCampaigns(args) {
|
|
163
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
return
|
|
170
|
+
return this.campaignsService.getAllCampaignsByProjectId(args);
|
|
165
171
|
});
|
|
166
172
|
}
|
|
167
173
|
}
|
|
@@ -7,19 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
const buildQueryParams = (args) => {
|
|
11
|
+
let queryParams = "";
|
|
12
|
+
Object.keys(args).forEach((key) => {
|
|
13
|
+
queryParams =
|
|
14
|
+
queryParams === ""
|
|
15
|
+
? queryParams + `${key}=${args[key]}`
|
|
16
|
+
: queryParams + "&" + `${key}=${args[key]}`;
|
|
17
|
+
});
|
|
18
|
+
return queryParams;
|
|
19
|
+
};
|
|
10
20
|
export class CampaignsService {
|
|
11
21
|
constructor(httpClient) {
|
|
12
22
|
this.httpClient = httpClient;
|
|
13
23
|
}
|
|
14
|
-
|
|
24
|
+
getAllCampaignsByProjectId(args) {
|
|
15
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
return error;
|
|
22
|
-
}
|
|
26
|
+
const PATH = args ? `campaigns?${buildQueryParams(args)}` : `campaigns`;
|
|
27
|
+
const { data } = yield this.httpClient.get(PATH);
|
|
28
|
+
return data;
|
|
23
29
|
});
|
|
24
30
|
}
|
|
25
31
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export declare const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export declare const SENT_EVENT_ID_KEY = "fuul.sent";
|
|
6
6
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Fuul {
|
|
|
7
7
|
private campaignsService;
|
|
8
8
|
constructor(apiKey: string);
|
|
9
9
|
init(): void;
|
|
10
|
+
events(): void;
|
|
10
11
|
checkApiKey(): void;
|
|
11
12
|
/**
|
|
12
13
|
* @param {EventType} name Event name.
|
|
@@ -29,12 +30,12 @@ export declare class Fuul {
|
|
|
29
30
|
/**
|
|
30
31
|
* Generates a tracking link for a referrer
|
|
31
32
|
* @param {string} address referrer address
|
|
32
|
-
* @param {string}
|
|
33
|
+
* @param {string} pid project id you want to refer the user
|
|
33
34
|
* @param {string} baseUrl base url of your app
|
|
34
35
|
* @returns {string} tracking link
|
|
35
36
|
*/
|
|
36
|
-
generateTrackingLink({ address,
|
|
37
|
-
|
|
37
|
+
generateTrackingLink({ address, pid, baseUrl, }: IGenerateTrackingLink): string;
|
|
38
|
+
getAllCampaigns(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
38
39
|
}
|
|
39
40
|
declare const _default: {
|
|
40
41
|
Fuul: typeof Fuul;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA0EjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4C;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAmB1B,IAAI;IAIJ,MAAM;IAON,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAuDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAG7E;;;;AAMD,wBAEE"}
|
|
@@ -3,6 +3,6 @@ import { CampaignDTO } from "./dtos.js";
|
|
|
3
3
|
export declare class CampaignsService {
|
|
4
4
|
private httpClient;
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
6
|
-
|
|
6
|
+
getAllCampaignsByProjectId(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAexC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,0BAA0B,CAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,WAAW,EAAE,CAAC;CAM1B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getSessionId: () => string | null;
|
|
2
2
|
export declare const getTrackingId: () => string | null;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getProjectId: () => string | null;
|
|
4
4
|
export declare const getReferrerId: () => string | null;
|
|
5
5
|
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PROJECT_ID_KEY, REFERRER_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "../constants.js";
|
|
2
2
|
export const getSessionId = () => localStorage.getItem(SESSION_ID_KEY);
|
|
3
3
|
export const getTrackingId = () => localStorage.getItem(TRACKING_ID_KEY);
|
|
4
|
-
export const
|
|
4
|
+
export const getProjectId = () => localStorage.getItem(PROJECT_ID_KEY);
|
|
5
5
|
export const getReferrerId = () => localStorage.getItem(REFERRER_ID_KEY);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuul/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fuul SDK",
|
|
6
6
|
"types": "./lib/esm/types/index.d.ts",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"lib/**/*"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"compile": "node compile.js",
|
|
13
12
|
"clean": "rm -rf ./lib",
|
|
14
13
|
"dev": "ts-node ./src/index.ts",
|
|
15
14
|
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|