This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository contains Optimizely Labs - a collection of self-contained tutorials demonstrating how to work with Optimizely data and developer tools. Each lab is published to optimizely.com/labs via a Contentful CMS integration.
/labs/: Each subdirectory is a self-contained lab with its own README.md (tutorial content), metadata.md (Contentful metadata), and any supporting code/resources/utils/: Python scripts for publishing and managing labs in Contentful CMS/templates/: Templates for creating new labs (new-content and link-to-existing-content).github/workflows/: CI/CD pipelines for automatic publishing to Contentful
The repository uses a Python-based publishing system that:
- Scans
/labs/for all lab directories (slugs) - Zips each lab's contents and uploads to S3
- Parses
metadata.md(YAML frontmatter) and README.md/index.md - Upserts lab entries to Contentful CMS
- Labs appear at
optimizely.com/labs/{slug}
Key files:
utils/publish.py: Main publishing script - zips labs, uploads to S3, syncs to Contentfulutils/delete.py: Deletes a specific lab from Contentfulutils/labs_constants.py: Configuration constants (paths, Contentful settings, S3 credentials)
- Slugs must match
^[a-zA-Z0-9-.]{1,64}$(alphanumeric, dashes, periods, underscores only) - Slugs serve as both directory names and Contentful entry IDs
- Slugs become URL paths:
optimizely.com/labs/{slug}
pip install -r requirements.txtPublishing happens automatically on push to master branch via GitHub Actions, but can be run manually:
# Set required environment variables (see labs_constants.py for full list)
export LABS_CONTENTFUL_ENVIRONMENT=master
export LABS_CONTENTFUL_SPACE_ID=zw48pl1isxmc
export LABS_CONTENTFUL_MANAGEMENT_API_TOKEN=<token>
export LIBRARY_URL=https://library.optimizely.com/
export LIBRARY_S3_BUCKET=library-optimizely-com
export LIBRARY_S3_ACCESS_KEY=<key>
export LIBRARY_S3_SECRET_KEY=<secret>
# Run publish script
python utils/publish.pyexport SLUG_TO_DELETE=<lab-slug>
export LABS_CONTENTFUL_ENVIRONMENT=master
export LABS_CONTENTFUL_SPACE_ID=zw48pl1isxmc
export LABS_CONTENTFUL_MANAGEMENT_API_TOKEN=<token>
python utils/delete.py- Create directory under
/labs/with a valid slug name - Add
README.mdusing template from/templates/new-content/README.mdor/templates/link-to-existing-content/README.md - Add
metadata.mdusing template from/templates/metadata.md - Set
excludeFromListing: truein metadata.md initially - Use absolute URLs for links/images (prefix with
https://raw.githubusercontent.com/optimizely/labs/master/for images) - Submit PR for review
- After merge, lab appears at
optimizely.com/labs/{slug} - When ready to feature, set
excludeFromListing: falsevia separate PR
README.md/index.md (content priority: index.md > README.md):
- Tutorial content in Markdown
- Should include: summary, pre-requisites, numbered steps
- Use absolute URLs for all links and images
metadata.md:
- YAML frontmatter with: title, summary, revisionDate, labels, author, seo, excludeFromListing
- Controls how lab appears in Contentful and on optimizely.com/labs
Labs cover various Optimizely integrations and use cases:
- Feature Flags: Python Flask, Ruby Sinatra examples
- Data Analysis: Spark/PySpark notebooks for Enriched Event data
- Integrations: Third-party integrations (ContentSquare, Crazy Egg, Zuko, Segment)
- Browser Extensions: Custom Optimizely editor extensions
- Event Targeting: Sequential events, custom targeting examples
Some labs (computing-experiment-metrics, query-enriched-event-data-with-spark) use:
- Docker for containerized execution
- PySpark for processing Optimizely Enriched Event data
- Jupyter Lab for interactive notebooks
- Python requirements.txt for lab-specific dependencies
Run these labs using:
bash bin/run.sh # Uses Docker (primary method)
bash bin/run-docker.sh # Direct Docker execution- Labs are self-contained - all resources should be within the lab directory
- Publishing is automatic on master branch commits
- Lab zips are uploaded to S3 and linked in Contentful as downloadable resources
- Metadata field
excludeFromListing: truehides labs from main listing page - Use GitHub Actions workflow "Contentful Delete" to manually delete labs