insert-affiliate-js-sdk 1.0.0 → 1.0.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/README.md +2 -2
- package/dist/index.js +11 -3
- package/package.json +1 -1
- package/src/sdk/InsertAffiliate.ts +13 -3
package/README.md
CHANGED
|
@@ -179,7 +179,7 @@ async function trackSignupEvent() {
|
|
|
179
179
|
|
|
180
180
|
### What are Short Codes?
|
|
181
181
|
|
|
182
|
-
Short codes are unique,
|
|
182
|
+
Short codes are unique, 3 to 25 character alphanumeric identifiers that affiliates can use to promote products or subscriptions. These codes are ideal for influencers or partners, making them easier to share than long URLs.
|
|
183
183
|
|
|
184
184
|
**Example Use Case**: An influencer promotes a subscription with the short code "JOIN123456" within their TikTok video's description. When users enter this code within your app during sign-up or before purchase, the app tracks the subscription back to the influencer for commission payouts.
|
|
185
185
|
|
|
@@ -190,7 +190,7 @@ For more information, visit the [Insert Affiliate Short Codes Documentation](htt
|
|
|
190
190
|
Use the `setShortCode` method to associate a short code with an affiliate. This is ideal for scenarios where users enter the code via an input field, pop-up, or similar UI element.
|
|
191
191
|
|
|
192
192
|
Short codes must meet the following criteria:
|
|
193
|
-
-
|
|
193
|
+
- Between **3 and 25 characters long**.
|
|
194
194
|
- Contain only **letters and numbers** (alphanumeric characters).
|
|
195
195
|
- Replace {{ user_entered_short_code }} with the short code the user enters through your chosen input method, i.e. an input field / pop up element
|
|
196
196
|
|
package/dist/index.js
CHANGED
|
@@ -93,13 +93,13 @@ var InsertAffiliate = class {
|
|
|
93
93
|
}
|
|
94
94
|
static async setInsertAffiliateIdentifier(referringLink) {
|
|
95
95
|
const userId = await this.getOrCreateUserID();
|
|
96
|
-
const shortCode = /^[a-zA-Z0-9]{
|
|
96
|
+
const shortCode = /^[a-zA-Z0-9]{3,25}$/.test(referringLink) ? referringLink : await this.fetchShortLink(referringLink);
|
|
97
97
|
if (!shortCode) return null;
|
|
98
98
|
await saveValue("referrerLink", shortCode);
|
|
99
99
|
return `${shortCode}-${userId}`;
|
|
100
100
|
}
|
|
101
101
|
static async setShortCode(shortCode) {
|
|
102
|
-
const valid = /^[a-zA-Z0-9]{
|
|
102
|
+
const valid = /^[a-zA-Z0-9]{3,25}$/.test(shortCode);
|
|
103
103
|
if (!valid) {
|
|
104
104
|
console.warn("[Insert Affiliate] Invalid short code.");
|
|
105
105
|
return;
|
|
@@ -112,11 +112,19 @@ var InsertAffiliate = class {
|
|
|
112
112
|
console.warn("[Insert Affiliate] No affiliate identifier found.");
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
+
const companyCode = this.companyCode || await getValue("companyCode");
|
|
116
|
+
if (!companyCode) return;
|
|
115
117
|
try {
|
|
116
118
|
await fetch("https://api.insertaffiliate.com/v1/trackEvent", {
|
|
117
119
|
method: "POST",
|
|
118
120
|
headers: { "Content-Type": "application/json" },
|
|
119
|
-
body: JSON.stringify(
|
|
121
|
+
body: JSON.stringify(
|
|
122
|
+
{
|
|
123
|
+
eventName,
|
|
124
|
+
deepLinkParam: id,
|
|
125
|
+
companyId: companyCode
|
|
126
|
+
}
|
|
127
|
+
)
|
|
120
128
|
});
|
|
121
129
|
console.log("[Insert Affiliate] Event tracked:", eventName);
|
|
122
130
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ export class InsertAffiliate {
|
|
|
43
43
|
|
|
44
44
|
static async setInsertAffiliateIdentifier(referringLink: string): Promise<string | null> {
|
|
45
45
|
const userId = await this.getOrCreateUserID();
|
|
46
|
-
const shortCode = /^[a-zA-Z0-9]{
|
|
46
|
+
const shortCode = /^[a-zA-Z0-9]{3,25}$/.test(referringLink)
|
|
47
47
|
? referringLink
|
|
48
48
|
: await this.fetchShortLink(referringLink);
|
|
49
49
|
|
|
@@ -54,7 +54,7 @@ export class InsertAffiliate {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
static async setShortCode(shortCode: string): Promise<void> {
|
|
57
|
-
const valid = /^[a-zA-Z0-9]{
|
|
57
|
+
const valid = /^[a-zA-Z0-9]{3,25}$/.test(shortCode);
|
|
58
58
|
if (!valid) {
|
|
59
59
|
console.warn('[Insert Affiliate] Invalid short code.');
|
|
60
60
|
return;
|
|
@@ -64,16 +64,26 @@ export class InsertAffiliate {
|
|
|
64
64
|
|
|
65
65
|
static async trackEvent(eventName: string): Promise<void> {
|
|
66
66
|
const id = await this.returnInsertAffiliateIdentifier();
|
|
67
|
+
|
|
67
68
|
if (!id) {
|
|
68
69
|
console.warn('[Insert Affiliate] No affiliate identifier found.');
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
const companyCode = this.companyCode || await getValue('companyCode');
|
|
74
|
+
|
|
75
|
+
if (!companyCode) return;
|
|
76
|
+
|
|
72
77
|
try {
|
|
73
78
|
await fetch('https://api.insertaffiliate.com/v1/trackEvent', {
|
|
74
79
|
method: 'POST',
|
|
75
80
|
headers: { 'Content-Type': 'application/json' },
|
|
76
|
-
body: JSON.stringify(
|
|
81
|
+
body: JSON.stringify(
|
|
82
|
+
{
|
|
83
|
+
eventName,
|
|
84
|
+
deepLinkParam: id,
|
|
85
|
+
companyId: companyCode,
|
|
86
|
+
}),
|
|
77
87
|
});
|
|
78
88
|
console.log('[Insert Affiliate] Event tracked:', eventName);
|
|
79
89
|
} catch (err) {
|