|
1 | | -# Agent Guidelines |
| 1 | +# Rokt Web Kit - Agent Instructions |
2 | 2 |
|
3 | | -Instructions for AI agents working on this repository. |
| 3 | +This file provides guidance for AI coding agents working with the Rokt web kit codebase. |
4 | 4 |
|
5 | | -## Branch Naming and Commit Conventions |
| 5 | +## About This Kit |
6 | 6 |
|
7 | | -Branch names must use a conventional commit prefix (e.g., `feat/`, `fix/`, `chore/`). This is enforced by CI. See `CONTRIBUTING.md` for the full list of allowed types and commit message format. |
| 7 | +The Rokt web kit (`@mparticle/web-rokt-kit`) is an mParticle integration kit (forwarder) that bridges the mParticle Web SDK and the Rokt Web SDK. It receives events from mParticle and forwards them to Rokt for placement selection, user targeting, and attribution. |
8 | 8 |
|
9 | | -## Do Not Commit Build Artifacts |
| 9 | +**Module ID**: 181 |
10 | 10 |
|
11 | | -The `dist/` folder, `CHANGELOG.md`, and version bumps in `package.json`/`package-lock.json` are all generated by the CI/CD release process. Only commit changes to source (`src/`) and test (`test/`) files. |
| 11 | +## Tech Stack |
12 | 12 |
|
13 | | -## Git Push (SAML SSO) |
| 13 | +- **Language**: Plain JavaScript project — kit source is ES5-style; tests/tooling may use ES6. There is no TypeScript compilation step. |
| 14 | +- **Build Tool**: Rollup (IIFE and CommonJS output) |
| 15 | +- **Testing**: Karma + Mocha/Chai (real browser tests in Chrome and Firefox) |
| 16 | +- **Package Manager**: npm |
| 17 | +- **Code Quality**: ESLint |
14 | 18 |
|
15 | | -The `mparticle-integrations` GitHub org enforces SAML SSO. SSH push will fail. To push: |
| 19 | +## Project Structure |
16 | 20 |
|
17 | | -1. Run `gh auth setup-git` to configure the git credential helper. |
18 | | -2. Temporarily switch the remote to HTTPS: `git remote set-url origin https://github.com/mparticle-integrations/mparticle-javascript-integration-rokt.git` |
19 | | -3. Push the branch. |
20 | | -4. Restore the SSH remote: `git remote set-url origin git@github.com:mparticle-integrations/mparticle-javascript-integration-rokt.git` |
| 21 | +``` |
| 22 | +/ |
| 23 | + src/ |
| 24 | + Rokt-Kit.js # Single monolithic source file (~900 lines) |
| 25 | + dist/ |
| 26 | + Rokt-Kit.iife.js # Browser bundle (IIFE) |
| 27 | + Rokt-Kit.common.js # npm bundle (CommonJS) |
| 28 | + test/ |
| 29 | + src/ |
| 30 | + tests.js # Mocha/Chai test suite |
| 31 | + config.js # Test mParticle configuration |
| 32 | + karma.config.js # Karma test runner config |
| 33 | + lib/ # Test utilities |
| 34 | + end-to-end-testapp/ # E2E test app |
| 35 | + rollup.config.js # Build configuration |
| 36 | + package.json |
| 37 | +``` |
21 | 38 |
|
22 | | -## Running Tests |
| 39 | +## Key Commands |
23 | 40 |
|
24 | 41 | ```bash |
25 | | -npm install |
26 | | -npm test -- --browsers ChromeHeadless # FirefoxHeadless may not be available |
| 42 | +npm run build # Build IIFE and CommonJS bundles |
| 43 | +npm run build:test # Build test bundle |
| 44 | +npm run lint # ESLint check (src/ and test/src/) |
| 45 | +npm run lint:fix # ESLint autofix |
| 46 | +npm run test # Build + build tests + run Karma |
| 47 | +npm run test:debug # Non-headless Chrome for debugging |
| 48 | +npm run watch # Watch and rebuild on changes |
27 | 49 | ``` |
28 | 50 |
|
29 | | -## Linting |
| 51 | +## Build Artifacts — Do Not Commit |
30 | 52 |
|
31 | | -```bash |
32 | | -npm run lint # check |
33 | | -npm run lint:fix # auto-fix |
34 | | -``` |
| 53 | +The `dist/` folder, `CHANGELOG.md`, and version bumps in `package.json`/`package-lock.json` are all generated by the CI/CD release process. **Do not commit these manually.** Only commit changes to source (`src/`) and test (`test/`) files. |
| 54 | + |
| 55 | +## Code Conventions |
| 56 | + |
| 57 | +- **Single source file**: All kit logic lives in `src/Rokt-Kit.js` |
| 58 | +- **Constructor function pattern**: `var constructor = function() { ... }` with `var self = this;` |
| 59 | +- **var declarations**: The codebase uses `var` throughout — match this style |
| 60 | +- **No TypeScript**: No type annotations, no interfaces, no generics |
| 61 | +- **Module registration**: Kit self-registers via `window.mParticle.addForwarder()` at load time |
| 62 | + |
| 63 | +## Architecture |
| 64 | + |
| 65 | +- Kit is an mParticle forwarder that self-registers via `window.mParticle.addForwarder()` at load time |
| 66 | +- Kit attaches to the Rokt manager: `window.mParticle.Rokt.attachKit(self)` |
| 67 | +- Rokt launcher loads asynchronously — events are queued until it's ready |
| 68 | +- Configuration comes from mParticle server-side kit settings |
| 69 | + |
| 70 | +## Testing Patterns |
| 71 | + |
| 72 | +- Tests use Mocha `describe`/`it` blocks with Chai `expect` assertions |
| 73 | +- mParticle SDK is mocked in test config |
| 74 | +- Rokt launcher is mocked with spy functions |
| 75 | +- `beforeEach` resets kit state between tests |
| 76 | +- Tests run in real browsers (Chrome, Firefox) via Karma |
| 77 | + |
| 78 | +## Common Gotchas |
| 79 | + |
| 80 | +1. **Single file**: All changes go in `src/Rokt-Kit.js` — there are no imports/modules |
| 81 | +2. **Browser-only**: Code runs in browser context, `window` is always available |
| 82 | +3. **Async launcher**: Rokt launcher loads asynchronously — events must be queued until ready |
| 83 | +4. **var scope**: Use `var` not `let`/`const` to match existing style |
| 84 | +5. **self reference**: Use `var self = this;` pattern for callback context |
| 85 | + |
| 86 | +## Available Skills |
35 | 87 |
|
36 | | -Always run lint before pushing. The CI enforces Prettier formatting. |
| 88 | +- **`/verify`**: Run lint, build, and tests to validate your changes. **You MUST run `/verify` before committing or opening a pull request.** Do not skip this step. See `.claude/skills/verify/skill.md`. |
0 commit comments