|
| 1 | +# Analytics Client Migration Plan |
| 2 | + |
| 3 | +This plan outlines the steps to extract the analytics client logic from `@metamask/sdk-communication-layer` into this new `@metamask/analytics-client` package. |
| 4 | + |
| 5 | +1. **Configure `package.json` for Public Release (`packages/analytics-client/package.json`):** |
| 6 | + |
| 7 | + - Ensure `name` is `@metamask/analytics-client`. |
| 8 | + - Set a starting `version` (e.g., `0.1.0`). |
| 9 | + - Set `private: false`. |
| 10 | + - Add essential public package fields: `description`, `license`, `homepage`, `bugs`, `repository`, `author` (copy/adapt from another public package like `@metamask/sdk-communication-layer`). |
| 11 | + - Define `main: "dist/src/index.js"` and `types: "dist/src/index.d.ts"`. |
| 12 | + - Add build/lint/test/clean scripts (copy/adapt from another package). |
| 13 | + - Add `dependencies`: `"cross-fetch": "latest"`, `"@metamask/sdk-communication-layer": "workspace:^"`. |
| 14 | + - Add standard `devDependencies` (`typescript`, `@types/node`, etc., adapt from another package). |
| 15 | + - Add `publishConfig: { "access": "public" }`. |
| 16 | + - Ensure `files` includes `dist/`. |
| 17 | + |
| 18 | +2. **Verify & Configure `tsconfig.json` (`packages/analytics-client/tsconfig.json`):** |
| 19 | + |
| 20 | + - Ensure it extends a base config if applicable (e.g., `../../tsconfig.base.json`). |
| 21 | + - Set `compilerOptions.outDir` to `"./dist"`. |
| 22 | + - Set `compilerOptions.rootDir` to `"./src"`. |
| 23 | + - Include `"src/**/*"` and exclude `node_modules`, `dist`. |
| 24 | + |
| 25 | +3. **Move Analytics Code:** |
| 26 | + |
| 27 | + - Move the file `packages/sdk-communication-layer/src/Analytics.ts` to `packages/analytics-client/src/Analytics.ts`. |
| 28 | + |
| 29 | +4. **Refactor Moved Code (`packages/analytics-client/src/Analytics.ts`):** |
| 30 | + |
| 31 | + - Update import paths for types (`TrackingEvents`, `OriginatorInfo`, `CommunicationLayerPreference`) to point to `@metamask/sdk-communication-layer`. |
| 32 | + - Remove the import and usage of the `logger` from `sdk-communication-layer`. (Logging within `SendAnalytics` can be revisited if necessary). |
| 33 | + |
| 34 | +5. **Export from New Package (`packages/analytics-client/src/index.ts`):** |
| 35 | + |
| 36 | + - Export `SendAnalytics` and `AnalyticsProps` from `./Analytics`. |
| 37 | + - Re-export `TrackingEvents`, `OriginatorInfo`, `CommunicationLayerPreference` from `@metamask/sdk-communication-layer` for consumer convenience. |
| 38 | + |
| 39 | +6. **Update Dependencies in Consuming Packages:** |
| 40 | + |
| 41 | + - In `packages/sdk/package.json`: Add `"@metamask/analytics-client": "workspace:^"` to `dependencies`. |
| 42 | + - In `packages/sdk-communication-layer/package.json`: Remove `"cross-fetch"` from `dependencies` (if it's no longer used elsewhere in that package). |
| 43 | + |
| 44 | +7. **Update SDK Code (`packages/sdk/src/services/Analytics.ts` & `Analytics.test.ts`):** |
| 45 | + |
| 46 | + - Change imports of `SendAnalytics`, `AnalyticsProps`, `TrackingEvents` from `@metamask/sdk-communication-layer` to `@metamask/analytics-client`. |
| 47 | + - Keep the import for `DEFAULT_SERVER_URL` pointing to `@metamask/sdk-communication-layer`. |
| 48 | + - Update the `jest.mock` path in `Analytics.test.ts` to `@metamask/analytics-client`. |
| 49 | + |
| 50 | +8. **Clean Up Communication Layer (`packages/sdk-communication-layer`):** |
| 51 | + |
| 52 | + - Delete the original `packages/sdk-communication-layer/src/Analytics.ts` file. |
| 53 | + - In `packages/sdk-communication-layer/src/index.ts`, remove the exports for `SendAnalytics` and `AnalyticsProps`. Keep exports for the shared types (`TrackingEvents`, `OriginatorInfo`, etc.). |
| 54 | + |
| 55 | +9. **Install & Build:** |
| 56 | + |
| 57 | + - Run `yarn install` at the workspace root to link the new package and update dependencies. |
| 58 | + - Run `yarn build` (or the appropriate workspace build command) at the root to compile the new package and check for errors. |
| 59 | + |
| 60 | +10. **Test:** |
| 61 | + - Run `yarn test` (or the appropriate workspace test command) at the root. Address any test failures, particularly in `packages/sdk`. |
0 commit comments