@amplifyup/sdk 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/README.md +43 -121
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,47 +1,60 @@
1
1
  # @amplifyup/sdk
2
2
 
3
- AmplifyUp Tracking SDK - CDP-agnostic event tracking library.
3
+ Official JavaScript SDK for [AmplifyUp](https://amplifyup.ai) — event tracking, page layouts, personalization, and Composer preview on your site.
4
4
 
5
- ## Overview
5
+ ## Install
6
6
 
7
- This SDK provides event tracking and personalization against AmplifyUp backends.
8
- Configure a `trackingId`, and optionally a `target` for which environment to use.
7
+ ```bash
8
+ npm install @amplifyup/sdk
9
+ ```
9
10
 
10
- ## Environment targets
11
+ ## Quick start
11
12
 
12
- **Default: production (live).** Hosting your site on `localhost` does not switch environments.
13
+ ### React / Next.js
13
14
 
14
- Opt into `local` only when developing inside the AmplifyUp monorepo:
15
+ Wrap your app with the provider and pass your site **tracking ID** from the AmplifyUp dashboard:
15
16
 
16
- | Target | When | Layouts / config | Events + personalize |
17
- |--------|------|------------------|----------------------|
18
- | `production` (default) | Customer sites, staging, production | `https://amplifyup.ai` | `https://api.amplifyup.ai` |
19
- | `local` (explicit) | AmplifyUp monorepo dev | `NEXT_PUBLIC_ORCHESTRATOR_URL` | `https://api-dev.amplifyup.ai` |
17
+ ```tsx
18
+ import { AmplifyUpProvider } from '@amplifyup/sdk/react';
20
19
 
21
- ```bash
22
- # AmplifyUp monorepo only (apps/demo, apps/orchestrator locally)
23
- NEXT_PUBLIC_ORCHESTRATOR_URL=http://localhost:5001
24
- NEXT_PUBLIC_AMPLIFYUP_TARGET=local
20
+ export default function RootLayout({ children }) {
21
+ return (
22
+ <AmplifyUpProvider config={{ trackingId: 'your-tracking-id' }}>
23
+ {children}
24
+ </AmplifyUpProvider>
25
+ );
26
+ }
27
+ ```
28
+
29
+ ### Track events
30
+
31
+ ```typescript
32
+ import { init, page, track, identify } from '@amplifyup/sdk';
33
+
34
+ await init({ trackingId: 'your-tracking-id' });
35
+
36
+ page('/home');
37
+
38
+ track('Product Viewed', { productId: '123' });
25
39
 
26
- # Customer sites: omit NEXT_PUBLIC_AMPLIFYUP_TARGET — always live
40
+ identify('user-123', { email: 'user@example.com' });
27
41
  ```
28
42
 
29
- Check active URLs in the browser: `AmplifyUp.getStatus()`
43
+ ## Composer and hybrid pages
30
44
 
31
- ### Hybrid pages (native content + Composer)
45
+ If a page has its own native content **and** can be edited in Composer, use `AmplifyPageContent`:
32
46
 
33
- For pages with native content that should only appear for real visitors:
47
+ - **Visitors** see your AmplifyUp layout, or your native content when no layout is configured yet.
48
+ - **Composer preview** shows only the layout canvas — native fallback content is hidden.
34
49
 
35
50
  ```tsx
36
- // app/insights/page.tsx (server)
37
51
  import { isPreviewRequest } from '@amplifyup/sdk';
38
52
  import { AmplifyPageContent } from '@amplifyup/sdk/react';
39
53
 
40
- export default async function InsightsPage({ searchParams }) {
54
+ export default async function Page({ searchParams }) {
41
55
  const params = await searchParams;
42
56
 
43
57
  if (isPreviewRequest(params)) {
44
- // Composer: no blog fetch, no native fallback HTML
45
58
  return (
46
59
  <Layout>
47
60
  <AmplifyPageContent renderComponent={renderAmplifyComponent} />
@@ -49,116 +62,25 @@ export default async function InsightsPage({ searchParams }) {
49
62
  );
50
63
  }
51
64
 
52
- const posts = await getPosts();
53
65
  return (
54
66
  <Layout>
55
- <PostsProvider value={posts}>
56
- <AmplifyPageContent
57
- fallback={<InsightsFallback />}
58
- renderComponent={renderAmplifyComponent}
59
- />
60
- </PostsProvider>
67
+ <AmplifyPageContent
68
+ fallback={<YourNativePage />}
69
+ renderComponent={renderAmplifyComponent}
70
+ />
61
71
  </Layout>
62
72
  );
63
73
  }
64
74
  ```
65
75
 
66
- In Composer preview, `AmplifyPageContent` shows an empty layout canvas — never `fallback`.
67
-
68
- ## Installation
69
-
70
- ```bash
71
- npm install @amplifyup/sdk
72
- ```
73
-
74
- ## Usage
76
+ ## Debugging
75
77
 
76
- ### Basic Setup
78
+ In the browser console (on your site):
77
79
 
78
- ```typescript
79
- import { init } from '@amplifyup/sdk';
80
-
81
- await init({
82
- trackingId: 'your-tracking-id',
83
- debug: true,
84
- });
85
- ```
86
-
87
- ### Track Events
88
-
89
- ```typescript
90
- import {
91
- page,
92
- track,
93
- trackClick,
94
- trackFormSubmit,
95
- trackContentView,
96
- identify
97
- } from '@amplifyup/sdk';
98
-
99
- // Track page view
100
- page('/home');
101
-
102
- // Track custom event
103
- track('Product Viewed', {
104
- productId: '123',
105
- productName: 'Widget',
106
- price: 29.99
107
- });
108
-
109
- // Track button click
110
- trackClick('add-to-cart', 'Add to Cart', {
111
- productId: '123'
112
- });
113
-
114
- // Track form submission
115
- trackFormSubmit('newsletter-signup', {
116
- email: 'user@example.com'
117
- });
118
-
119
- // Track content view
120
- trackContentView('product-123', 'product', {
121
- productName: 'Widget',
122
- category: 'Electronics'
123
- });
124
-
125
- // Identify user
126
- identify('user-123', {
127
- email: 'user@example.com',
128
- name: 'John Doe'
129
- });
130
- ```
131
-
132
- ### Get Instance ID
133
-
134
- ```typescript
135
- import { getInstanceId } from '@amplifyup/sdk';
136
-
137
- const instanceId = getInstanceId();
138
- ```
139
-
140
- ## Architecture
141
-
142
- The SDK sends events directly to AWS API Gateway:
143
- - Events are sent to `/v1/track` or `/v1/page` endpoints
144
- - All URLs are hardcoded in the SDK
145
- - No write keys or configuration needed
146
- - Personalization requests go to AWS Decision API Gateway
147
-
148
- ## Development
149
-
150
- ```bash
151
- # Build
152
- npm run build
153
-
154
- # Watch mode
155
- npm run dev
156
-
157
- # Lint
158
- npm run lint
80
+ ```js
81
+ AmplifyUp.getStatus()
159
82
  ```
160
83
 
161
84
  ## License
162
85
 
163
86
  MIT
164
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplifyup/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "AmplifyUp Tracking SDK - CDP-agnostic event tracking library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",