@getforty/widget 0.1.0

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.

Potentially problematic release.


This version of @getforty/widget might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GetForty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # @getforty/widget
2
+
3
+ Embeddable feedback widget and event tracking SDK for GetForty.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @getforty/widget
9
+ ```
10
+
11
+ Or include via CDN:
12
+
13
+ ```html
14
+ <script src="https://unpkg.com/@getforty/widget@latest/dist/index.global.js"></script>
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ### ES Module
20
+
21
+ ```typescript
22
+ import { GetForty } from "@getforty/widget";
23
+
24
+ const widget = await GetForty.init({
25
+ trackingId: "gf_xxxxxxxxxxxx", // Your workspace tracking ID
26
+ });
27
+
28
+ // Track events
29
+ widget.track("page_view", { page: "/pricing" });
30
+
31
+ // Identify users
32
+ widget.identify("user_123", { email: "user@example.com", plan: "pro" });
33
+
34
+ // Show feedback form
35
+ widget.showForm("my-feedback-form");
36
+ ```
37
+
38
+ ### Script Tag
39
+
40
+ ```html
41
+ <script src="https://unpkg.com/@getforty/widget@latest/dist/index.global.js"></script>
42
+ <script>
43
+ GetFortyWidget.GetForty.init({
44
+ trackingId: "gf_xxxxxxxxxxxx",
45
+ }).then(function (widget) {
46
+ widget.track("page_view");
47
+ });
48
+ </script>
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ ```typescript
54
+ const widget = await GetForty.init({
55
+ // Required
56
+ trackingId: "gf_xxxxxxxxxxxx",
57
+
58
+ // Optional - Form display
59
+ mode: "modal", // 'modal' or 'inline'
60
+ container: "#widget-container", // Container for inline mode
61
+
62
+ // Optional - Appearance
63
+ showBranding: true, // Show "Powered by GetForty"
64
+ theme: {
65
+ primaryColor: "#6366f1",
66
+ backgroundColor: "#ffffff",
67
+ textColor: "#1f2937",
68
+ fontFamily: "Inter, sans-serif",
69
+ borderRadius: "8px",
70
+ },
71
+
72
+ // Optional - Localization
73
+ locale: "en", // 'en' or 'pt-BR'
74
+ translations: {
75
+ // Custom strings
76
+ submit: "Send Feedback",
77
+ success: "Thanks for your feedback!",
78
+ },
79
+
80
+ // Optional - Tracking
81
+ autoTrackPageViews: true, // Auto-track page views
82
+
83
+ // Optional - Development
84
+ debug: false, // Enable debug logging
85
+ apiBaseUrl: "https://getforty.club", // API endpoint
86
+ });
87
+ ```
88
+
89
+ ## API
90
+
91
+ ### `GetForty.init(config)`
92
+
93
+ Initialize the widget with your configuration. Returns a Promise that resolves to a widget instance.
94
+
95
+ ### `widget.track(eventName, properties?)`
96
+
97
+ Track a custom event.
98
+
99
+ ```typescript
100
+ widget.track("purchase", {
101
+ product: "Pro Plan",
102
+ amount: 99.99,
103
+ currency: "USD",
104
+ });
105
+ ```
106
+
107
+ ### `widget.identify(userId, traits?)`
108
+
109
+ Identify the current user. Call this when a user logs in.
110
+
111
+ ```typescript
112
+ widget.identify("user_123", {
113
+ email: "user@example.com",
114
+ name: "John Doe",
115
+ plan: "pro",
116
+ });
117
+ ```
118
+
119
+ ### `widget.showForm(formId)`
120
+
121
+ Display a feedback form programmatically.
122
+
123
+ ```typescript
124
+ widget.showForm("clxxxxxxxxxxxxxxxxx");
125
+ ```
126
+
127
+ ### `widget.hideForm()`
128
+
129
+ Hide the currently displayed form.
130
+
131
+ ### `widget.flush()`
132
+
133
+ Immediately send any queued events.
134
+
135
+ ```typescript
136
+ await widget.flush();
137
+ ```
138
+
139
+ ### `widget.getSessionId()`
140
+
141
+ Get the current session ID.
142
+
143
+ ```typescript
144
+ const sessionId = widget.getSessionId();
145
+ ```
146
+
147
+ ## Events
148
+
149
+ Subscribe to widget lifecycle events:
150
+
151
+ ```typescript
152
+ // Form loading
153
+ widget.on("load:start", ({ formId }) => {
154
+ console.log("Loading form:", formId);
155
+ });
156
+
157
+ widget.on("load:success", ({ form }) => {
158
+ console.log("Form loaded:", form.title);
159
+ });
160
+
161
+ widget.on("load:error", ({ error, retryable }) => {
162
+ console.error("Failed to load form:", error);
163
+ });
164
+
165
+ // Form submission
166
+ widget.on("submit:start", ({ answers }) => {
167
+ console.log("Submitting...", answers);
168
+ });
169
+
170
+ widget.on("submit:success", ({ responseId }) => {
171
+ console.log("Submitted! Response ID:", responseId);
172
+ });
173
+
174
+ widget.on("submit:error", ({ error, retryable }) => {
175
+ console.error("Submission failed:", error);
176
+ });
177
+
178
+ // Modal/form visibility
179
+ widget.on("open", ({ mode }) => {
180
+ console.log("Form opened in", mode, "mode");
181
+ });
182
+
183
+ widget.on("close", ({ reason }) => {
184
+ console.log("Form closed:", reason); // 'user', 'submitted', or 'programmatic'
185
+ });
186
+
187
+ // Generic errors
188
+ widget.on("error", ({ type, message }) => {
189
+ console.error(`${type} error:`, message);
190
+ });
191
+ ```
192
+
193
+ Unsubscribe from events:
194
+
195
+ ```typescript
196
+ const handleSuccess = ({ responseId }) => {
197
+ console.log("Submitted:", responseId);
198
+ };
199
+
200
+ widget.on("submit:success", handleSuccess);
201
+ widget.off("submit:success", handleSuccess);
202
+ ```
203
+
204
+ ## Localization
205
+
206
+ Built-in support for English and Portuguese (Brazil):
207
+
208
+ ```typescript
209
+ const widget = await GetForty.init({
210
+ trackingId: "gf_xxxxxxxxxxxx",
211
+ locale: "pt-BR", // Use Portuguese
212
+ });
213
+ ```
214
+
215
+ Custom translations:
216
+
217
+ ```typescript
218
+ const widget = await GetForty.init({
219
+ trackingId: "gf_xxxxxxxxxxxx",
220
+ locale: "en",
221
+ translations: {
222
+ submit: "Send",
223
+ success: "Thanks!",
224
+ required: "Please fill this in",
225
+ },
226
+ });
227
+ ```
228
+
229
+ ## Theming
230
+
231
+ Customize the widget appearance:
232
+
233
+ ```typescript
234
+ const widget = await GetForty.init({
235
+ trackingId: "gf_xxxxxxxxxxxx",
236
+ theme: {
237
+ primaryColor: "#3b82f6", // Buttons, active states
238
+ backgroundColor: "#f8fafc", // Widget background
239
+ textColor: "#0f172a", // Text color
240
+ fontFamily: "system-ui", // Font family
241
+ borderRadius: "12px", // Border radius
242
+ },
243
+ });
244
+ ```
245
+
246
+ ## TypeScript Support
247
+
248
+ Full TypeScript support with exported types:
249
+
250
+ ```typescript
251
+ import type {
252
+ WidgetConfig,
253
+ WidgetTheme,
254
+ WidgetEventMap,
255
+ TrackEventOptions,
256
+ FormConfig,
257
+ Answer,
258
+ } from "@getforty/widget";
259
+ ```
260
+
261
+ ## Browser Support
262
+
263
+ - Chrome (last 2 versions)
264
+ - Firefox (last 2 versions)
265
+ - Safari (last 2 versions)
266
+ - Edge (last 2 versions)
267
+
268
+ ## Bundle Size
269
+
270
+ - ~25KB gzipped (includes Preact runtime)
271
+ - Shadow DOM for style isolation
272
+ - No external dependencies at runtime
273
+
274
+ ## License
275
+
276
+ MIT