Skip to content

Commit 9ecf970

Browse files
authored
feat: update angular docs for new sdk (#79)
1 parent 6f3cebb commit 9ecf970

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

install.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,14 @@ Make sure you use the same `<SDK_WRITE_KEY>` for both your website and your app.
643643
Working example: [with-angular](https://github.com/getformo/examples/tree/main/with-angular). Also see the [Angular section](/sdks/web#angular) of the Web SDK page.
644644
</Note>
645645

646-
Angular has no first-class Formo binding — `FormoAnalyticsProvider` and `useFormo()` are React-only. Angular apps install Formo on the **non-wagmi, non-React path**: the framework-agnostic `FormoAnalytics.init()` core wrapped in an injectable service, with wallets connected over the bare EIP-1193 provider (`window.ethereum`).
646+
Angular has no first-class Formo binding — `FormoAnalyticsProvider` and `useFormo()` are React-only. Angular apps install Formo on the **non-wagmi, non-React path**: import the framework-agnostic `FormoAnalytics.init()` core from the [`@formo/analytics/core`](https://github.com/getformo/sdk/releases/tag/v1.30.1) subpath (added in **v1.30.1**), wrap it in an injectable service, and connect wallets over the bare EIP-1193 provider (`window.ethereum`).
647647

648648
#### 1. Install the Formo SDK
649649

650-
Install the SDK along with the `buffer` polyfill (Angular's esbuild build doesn't auto-polyfill Node globals, but the SDK uses `Buffer` to decode signed-message payloads) and viem:
650+
Install the SDK (v1.30.1 or later) along with the `buffer` polyfill (Angular's esbuild build doesn't auto-polyfill Node globals, but the SDK uses `Buffer` to decode signed-message payloads) and viem:
651651

652652
```bash
653-
pnpm add @formo/analytics buffer viem
653+
pnpm add @formo/analytics@^1.30.1 buffer viem
654654
pnpm add -D @ngx-env/builder
655655
```
656656

@@ -662,24 +662,26 @@ Make sure you use the same `<SDK_WRITE_KEY>` for both your website and your app.
662662
(globalThis as unknown as { Buffer?: typeof Buffer }).Buffer ??= Buffer;
663663
```
664664

665-
Reference it from `angular.json` and silence the SDK's React-re-export warnings:
665+
Reference it from `angular.json`. Importing from `@formo/analytics/core` (step 2) keeps React out of the dependency graph, so only `viem` needs to be allowlisted for CommonJS:
666666

667667
```jsonc
668668
// angular.json (build > options)
669669
{
670670
"polyfills": ["src/polyfills.ts"],
671-
"allowedCommonJsDependencies": ["react", "react/jsx-runtime", "react-dom", "viem"]
671+
"allowedCommonJsDependencies": ["viem"]
672672
}
673673
```
674674

675675
#### 2. Wrap `FormoAnalytics.init()` in an injectable service
676676

677+
Import from `@formo/analytics/core` — the root entry re-exports the React provider, which Angular doesn't need:
678+
677679
```ts
678680
// src/app/services/formo-analytics.service.ts
679681

680682
import { Injectable } from '@angular/core';
681-
import { FormoAnalytics } from '@formo/analytics';
682-
import type { IFormoAnalytics, IFormoEventProperties } from '@formo/analytics';
683+
import { FormoAnalytics } from '@formo/analytics/core';
684+
import type { IFormoAnalytics, IFormoEventProperties } from '@formo/analytics/core';
683685

684686
@Injectable({ providedIn: 'root' })
685687
export class FormoAnalyticsService {

sdks/web.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ export default HomePage;
147147
### Angular
148148

149149
<Note>
150-
`FormoAnalyticsProvider` and `useFormo()` are React-only. Angular apps use the framework-agnostic `FormoAnalytics.init()` core, wrapped in an injectable service, with wallets connected over the bare EIP-1193 provider (`window.ethereum`). Full working example: [with-angular](https://github.com/getformo/examples/tree/main/with-angular).
150+
`FormoAnalyticsProvider` and `useFormo()` are React-only. Angular apps import from the React-free [`@formo/analytics/core`](https://github.com/getformo/sdk/releases/tag/v1.30.1) subpath (added in **v1.30.1**) and wrap `FormoAnalytics.init()` in an injectable service, with wallets connected over the bare EIP-1193 provider (`window.ethereum`). Full working example: [with-angular](https://github.com/getformo/examples/tree/main/with-angular).
151151
</Note>
152152

153-
Install the Web SDK along with the `buffer` polyfill. Angular's esbuild build doesn't auto-polyfill Node globals, but the SDK uses `Buffer` to decode signed-message payloads — without it, signing throws `ReferenceError: Buffer is not defined`.
153+
Install the Web SDK (v1.30.1 or later) along with the `buffer` polyfill. Angular's esbuild build doesn't auto-polyfill Node globals, but the SDK uses `Buffer` to decode signed-message payloads — without it, signing throws `ReferenceError: Buffer is not defined`.
154154

155155
```bash
156-
npm install @formo/analytics buffer viem --save
156+
npm install @formo/analytics@^1.30.1 buffer viem --save
157157
```
158158

159159
```ts
@@ -166,17 +166,17 @@ import { Buffer } from 'buffer';
166166
// angular.json (build > options)
167167
{
168168
"polyfills": ["src/polyfills.ts"],
169-
"allowedCommonJsDependencies": ["react", "react/jsx-runtime", "react-dom", "viem"]
169+
"allowedCommonJsDependencies": ["viem"]
170170
}
171171
```
172172

173-
Wrap `FormoAnalytics.init()` in an injectable service:
173+
Wrap `FormoAnalytics.init()` in an injectable service. Import from `@formo/analytics/core` — the root entry pulls in the React provider, which Angular doesn't need:
174174

175175
```ts
176176
// src/app/services/formo-analytics.service.ts
177177
import { Injectable } from '@angular/core';
178-
import { FormoAnalytics } from '@formo/analytics';
179-
import type { IFormoAnalytics, IFormoEventProperties } from '@formo/analytics';
178+
import { FormoAnalytics } from '@formo/analytics/core';
179+
import type { IFormoAnalytics, IFormoEventProperties } from '@formo/analytics/core';
180180

181181
@Injectable({ providedIn: 'root' })
182182
export class FormoAnalyticsService {

0 commit comments

Comments
 (0)