|
| 1 | +# AI Agent Guide for Conversions API Parameter Builder SDK |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +The Conversions API Parameter Builder SDK is a multi-language toolkit designed |
| 6 | +to improve the quality of Conversions API parameter retrieval and validation. |
| 7 | +The SDK ensures event parameters adhere to best practices across multiple |
| 8 | +platforms. |
| 9 | + |
| 10 | +**Repository:** https://github.com/facebook/capi-param-builder |
| 11 | + |
| 12 | +### Supported Languages |
| 13 | + |
| 14 | +- **Server-side:** PHP, Java, NodeJS, Python, Ruby |
| 15 | +- **Client-side:** JavaScript |
| 16 | + |
| 17 | +Each language implementation lives in its own top-level directory with its own |
| 18 | +build system, tests, examples, and documentation. |
| 19 | + |
| 20 | +## Project Structure |
| 21 | + |
| 22 | +``` |
| 23 | +param_sdk/ |
| 24 | +├── README.md # Main project documentation |
| 25 | +├── AGENTS.md # AI Agent guidance (this file) |
| 26 | +├── CODE_OF_CONDUCT.md # Code of conduct |
| 27 | +├── CONTRIBUTING.md # Contribution guidelines |
| 28 | +├── LICENSE # License file |
| 29 | +├── composer.json # PHP root composer file |
| 30 | +├── .github/workflows/ # CI/CD workflows for all languages |
| 31 | +├── java/ # Java implementation |
| 32 | +├── nodejs/ # Node.js implementation |
| 33 | +├── php/ # PHP implementation |
| 34 | +├── python/ # Python implementation |
| 35 | +└── ruby/ # Ruby implementation |
| 36 | +``` |
| 37 | + |
| 38 | +**Note:** The `client_js/` directory is **not open-sourced** yet, the dir only |
| 39 | +contains examples. |
| 40 | + |
| 41 | +Each language directory follows a consistent structure: |
| 42 | + |
| 43 | +``` |
| 44 | +<language>/ |
| 45 | +├── README.md # Language-specific quick start guide |
| 46 | +├── CHANGELOG.md # Version history and changes |
| 47 | +├── CONTRIBUTING.md # Contribution guidelines |
| 48 | +├── CODE_OF_CONDUCT.md # Code of conduct |
| 49 | +├── LICENSE # License file |
| 50 | +├── capi-param-builder/ # Main SDK implementation (Python/Ruby use capi_param_builder with underscore) |
| 51 | +│ ├── src/ # Source code |
| 52 | +│ ├── tests/ or test/ # Unit tests |
| 53 | +│ └── ... # Language-specific build files |
| 54 | +└── example/ or examples/ # Example usage code (PHP uses "examples") |
| 55 | +``` |
| 56 | + |
| 57 | +## Core Functionality |
| 58 | + |
| 59 | +The SDK provides utilities for: |
| 60 | + |
| 61 | +- **Cookie parameter extraction** - Facebook click identifier (fbc) and browser |
| 62 | + identifier (fbp) |
| 63 | +- **Client IP address retrieval** - Enhanced mechanisms for capturing client IP |
| 64 | + addresses with IPv6 support (IPv4 fallback when IPv6 is unavailable) |
| 65 | +- **Customer Information Parameters normalization and hashing** - Tools to help |
| 66 | + adopt best practices for normalizing and hashing customer information |
| 67 | + including email, phone, name (first and last), address (city, state, zip code, |
| 68 | + country), gender, date of birth, external ID |
| 69 | + |
| 70 | +For details on features, refer to the |
| 71 | +[Parameter Builder Library](https://developers.facebook.com/docs/marketing-api/conversions-api/parameter-builder-feature-library). |
| 72 | + |
| 73 | +## Testing and Validation |
| 74 | + |
| 75 | +### Critical Rule: Always Run Tests Before Committing Changes |
| 76 | + |
| 77 | +**MANDATORY:** After making any code changes to a language implementation, you |
| 78 | +MUST run the appropriate test command for that language before considering the |
| 79 | +task complete. |
| 80 | + |
| 81 | +### Test Commands by Language |
| 82 | + |
| 83 | +#### Node.js |
| 84 | + |
| 85 | +```bash |
| 86 | +cd nodejs/capi-param-builder |
| 87 | +npm install |
| 88 | +npm test |
| 89 | +``` |
| 90 | + |
| 91 | +Tested on Node.js versions: 18.x, 20.x, 22.x, 24.x |
| 92 | + |
| 93 | +#### Python |
| 94 | + |
| 95 | +```bash |
| 96 | +cd python/capi_param_builder |
| 97 | +python3 -m unittest test/test_param_builder.py |
| 98 | +``` |
| 99 | + |
| 100 | +Tested on Python versions: 3.9, 3.10, 3.11 |
| 101 | + |
| 102 | +#### Java |
| 103 | + |
| 104 | +```bash |
| 105 | +cd java/capi-param-builder |
| 106 | +chmod +x ./gradlew |
| 107 | +./gradlew build |
| 108 | +``` |
| 109 | + |
| 110 | +Tested on Java versions: 8, 11, 17, 21 |
| 111 | + |
| 112 | +#### PHP |
| 113 | + |
| 114 | +```bash |
| 115 | +cd php/capi-param-builder |
| 116 | +composer install --dev --prefer-source |
| 117 | +./vendor/bin/phpunit ./tests/ --debug |
| 118 | +``` |
| 119 | + |
| 120 | +Tested on PHP versions: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 |
| 121 | + |
| 122 | +#### Ruby |
| 123 | + |
| 124 | +```bash |
| 125 | +cd ruby/capi_param_builder |
| 126 | +gem install minitest |
| 127 | +ruby -Ilib:test test/test_param_builder.rb |
| 128 | +``` |
| 129 | + |
| 130 | +Tested on Ruby versions: 3.0, 3.2, 3.3 |
| 131 | + |
| 132 | +## Making Code Changes |
| 133 | + |
| 134 | +### Language-Specific Considerations |
| 135 | + |
| 136 | +1. **Maintain API Consistency**: All language implementations should provide |
| 137 | + equivalent functionality with language-appropriate idioms. When adding a |
| 138 | + feature to one language, consider whether it should be added to others. |
| 139 | + |
| 140 | +2. **Backward Compatibility**: The SDK is used by external developers. We |
| 141 | + strongly recommend maintaining backward compatibility with existing flows. |
| 142 | + Breaking changes require: |
| 143 | + - Version bump (follow semantic versioning) |
| 144 | + - Changelog entry |
| 145 | + - Migration guide if necessary |
| 146 | + |
| 147 | +3. **Human Review for Intrusive Changes**: If you have intrusive changes that |
| 148 | + could break existing integrations or significantly alter SDK behavior, please |
| 149 | + ensure human review before implementation. Always prefer backward-compatible |
| 150 | + solutions over breaking changes. |
| 151 | + |
| 152 | +### Common File Locations |
| 153 | + |
| 154 | +**Note:** Python and Ruby use `capi_param_builder` (with underscores) instead of |
| 155 | +`capi-param-builder` (with dashes). |
| 156 | + |
| 157 | +- **Core logic:** `<language>/capi-param-builder/src/` (or `capi_param_builder/` |
| 158 | + for Python/Ruby) |
| 159 | +- **Tests:** `<language>/capi-param-builder/tests/` or |
| 160 | + `<language>/capi-param-builder/test/` (or `capi_param_builder/` for |
| 161 | + Python/Ruby) |
| 162 | +- **Models:** `<language>/capi-param-builder/src/model/` or similar (or |
| 163 | + `capi_param_builder/` for Python/Ruby) |
| 164 | +- **Utilities:** `<language>/capi-param-builder/src/utils/` (or |
| 165 | + `capi_param_builder/` for Python/Ruby) |
| 166 | + |
| 167 | +### Workflow for Adding Features |
| 168 | + |
| 169 | +1. **Research existing implementation** - Check if similar functionality exists |
| 170 | + in other language implementations |
| 171 | +2. **Update the implementation** - Add code to `src/` directory |
| 172 | +3. **Add tests** - Create or update test files with comprehensive test coverage |
| 173 | +4. **Run tests locally** - Use the appropriate test command for the language |
| 174 | +5. **Update documentation** - Update README.md and add inline code documentation |
| 175 | +6. **Update CHANGELOG.md** - Document the change following existing format |
| 176 | +7. **Bump version** - If the code change needs to be released, bump the version |
| 177 | + number following semantic versioning (see Version Files section below) |
| 178 | +8. **Test examples** - Verify example code still works if applicable |
| 179 | + |
| 180 | +### Version Files by Language |
| 181 | + |
| 182 | +When bumping versions, update the version number in these files: |
| 183 | + |
| 184 | +- **Node.js**: `nodejs/capi-param-builder/package.json` |
| 185 | +- **Python**: `python/capi_param_builder/setup.py` |
| 186 | +- **Java**: `java/capi-param-builder/build.gradle` and `java/build.gradle` |
| 187 | +- **PHP**: `php/capi-param-builder/composer.json` and `composer.json` |
| 188 | +- **Ruby**: `ruby/capi_param_builder/capi_param_builder.gemspec` with |
| 189 | + `ruby/capi_param_builder/lib/release_config.rb` |
| 190 | + |
| 191 | +**Note:** For Client-side JavaScript (Meta Internal Only), see the dedicated |
| 192 | +section above. |
| 193 | + |
| 194 | +### Workflow for Fixing Bugs |
| 195 | + |
| 196 | +1. **Reproduce the issue** - Write a failing test that demonstrates the bug |
| 197 | +2. **Fix the implementation** - Make targeted changes to source code |
| 198 | +3. **Verify the fix** - Ensure the new test passes |
| 199 | +4. **Run full test suite** - Confirm no regressions |
| 200 | +5. **Update CHANGELOG.md** - Document the bug fix |
| 201 | +6. **Bump version** - If the bug fix needs to be released, bump the version |
| 202 | + number following semantic versioning |
| 203 | +7. **Check other languages** - Verify if the same bug exists in other |
| 204 | + implementations |
| 205 | + |
| 206 | +## CI/CD Pipeline |
| 207 | + |
| 208 | +Each language has its own CI workflow in `.github/workflows/`: |
| 209 | + |
| 210 | +- `<language>_ci.yml` - Continuous integration (runs tests) |
| 211 | +- `<language>_cd.yml` - Continuous deployment (publishes packages) |
| 212 | + |
| 213 | +CI runs automatically on: |
| 214 | + |
| 215 | +- Push to any branch (for changed files in that language's directory) |
| 216 | +- Pull requests |
| 217 | +- Manual workflow dispatch |
| 218 | + |
| 219 | +The CI matrix tests against multiple versions of each language runtime to ensure |
| 220 | +compatibility. |
| 221 | + |
| 222 | +## Best Practices |
| 223 | + |
| 224 | +### Code Quality |
| 225 | + |
| 226 | +- Follow language-specific conventions and style guides |
| 227 | +- Keep functions focused and testable |
| 228 | +- Add meaningful comments for complex logic |
| 229 | +- Use descriptive variable and function names |
| 230 | + |
| 231 | +### Testing |
| 232 | + |
| 233 | +- Write unit tests for all new functionality |
| 234 | +- Test edge cases (null, empty, invalid input) |
| 235 | +- Mock external dependencies when appropriate |
| 236 | + |
| 237 | +### Documentation |
| 238 | + |
| 239 | +- Update README.md for public API changes |
| 240 | +- Add inline documentation for complex functions |
| 241 | +- Include usage examples for new features |
| 242 | +- Keep CHANGELOG.md up to date |
| 243 | + |
| 244 | +### Version Control |
| 245 | + |
| 246 | +- Make focused commits with clear messages |
| 247 | +- Reference issue numbers in commit messages |
| 248 | +- Keep changes scoped to single language when possible |
| 249 | +- Run tests before pushing |
| 250 | + |
| 251 | +## Common Tasks |
| 252 | + |
| 253 | +### Updating a shared constant |
| 254 | + |
| 255 | +1. Find the constants file (e.g., `Constants.js`, `constants.py`) |
| 256 | +2. Update the constant value |
| 257 | +3. Check for tests that may be affected |
| 258 | +4. Run full test suite |
| 259 | +5. Update any dependent example code |
| 260 | + |
| 261 | +### Adding a new parameter to the builder |
| 262 | + |
| 263 | +1. Update the main builder class (e.g., `ParamBuilder.js`, `param_builder.py`) |
| 264 | +2. Add validation logic if needed |
| 265 | +3. Add tests for the new parameter |
| 266 | +4. Update examples to show usage |
| 267 | +5. Document in README.md |
| 268 | + |
| 269 | +## External Resources |
| 270 | + |
| 271 | +- [Parameter Builder Library Overview](https://developers.facebook.com/docs/marketing-api/conversions-api/parameter-builder-feature-library) |
| 272 | +- [Conversions API Documentation](https://developers.facebook.com/docs/marketing-api/conversions-api) |
| 273 | +- Language-specific READMEs in each directory |
| 274 | + |
| 275 | +## Troubleshooting |
| 276 | + |
| 277 | +### Tests failing after changes |
| 278 | + |
| 279 | +1. Read the error message carefully - test frameworks provide specific failure |
| 280 | + details |
| 281 | +2. Run tests in isolation to identify the failing test |
| 282 | +3. Check if changes affected shared utilities or constants |
| 283 | +4. Verify all dependencies are installed |
| 284 | + |
| 285 | +### CI pipeline failures |
| 286 | + |
| 287 | +1. Check the specific workflow that failed (language-specific) |
| 288 | +2. Review the GitHub Actions logs for error details |
| 289 | +3. Ensure changes work on all tested language versions |
| 290 | +4. Verify no uncommitted files are required |
| 291 | + |
| 292 | +### Dependency issues |
| 293 | + |
| 294 | +1. Check package manager files for each language: |
| 295 | + - Node.js: `package.json` |
| 296 | + - Python: `setup.py` |
| 297 | + - Java: `build.gradle` |
| 298 | + - PHP: `composer.json` |
| 299 | + - Ruby: `capi_param_builder.gemspec` |
| 300 | +2. Ensure versions are compatible with the tested runtime versions |
| 301 | +3. Run clean install (delete `node_modules`, `.gradle`, cache, etc. and |
| 302 | + reinstall) |
| 303 | + |
| 304 | +## Important Notes |
| 305 | + |
| 306 | +- **Never commit secrets or credentials** - This is a public open-source project |
| 307 | +- **Cross-language consistency** - Keep APIs and behavior consistent across |
| 308 | + implementations |
| 309 | +- **Semantic versioning** - Follow semver for version bumps |
| 310 | +- **Run tests before submitting** - All tests must pass before changes are |
| 311 | + complete |
0 commit comments