Communityライティング&編集github.com

CQL の記述とデバッグ

Croct のコンテキストクエリ言語(CQL)でオーディエンス条件、評価クエリ、動的コンテンツ式を記述、レビュー、デバッグするためのスキル。

CQL の記述とデバッグ とは?

このスキルは、Croct のコンテキストクエリ言語(CQL)を使用する開発者や AI エージェント向けに設計されています。CQL は、オーディエンス定義、リアルタイム評価(SDK や HTTP API 経由)、動的コンテンツ値にわたって一貫した構文を提供する、英語に似たクエリ言語です。このスキルは、`croct.evaluate()`、`useEvaluation`、Next.js の `cql` タグ、Evaluation API の `query` ボディ、動的コンテンツの JSON 構造など、CQL が登場するあらゆる場面をカバーします。サポートされるプラットフォームは、Croct Plug(React、Next.js)、HTTP API、および Croct ダッシュボードです。このスキルは、クイックリファレンスのチートシート、一般的なパターン、トラブルシューティングガイドを提供し、構文エラー、型の不一致、定量子の優先順位、未定義値の処理などの落とし穴に対処します。また、ユーザープロファイル、セッション、ページ、場所、キャンペーン、カート、デバイス、ブラウザ、イベント式などのコンテキスト変数もカバーし、プロパティタイプ、アクセサ、修飾子、マクロ、条件文も含まれます。`croct-integrate-sdk` や `croct-track-events` などの関連スキルと組み合わせて使用することで、完全なパーソナライゼーションワークフローを実現できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/croct-tech/agent-skills/tree/HEAD/skills/croct-cql

Installed? Explore more ライティング&編集 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

CQL の記述とデバッグ は何をしますか?

CQL は Croct の英語ライクなクエリ言語です。同じ式の構文が、オーディエンス、SDK および HTTP API からのリアルタイム評価、動的コンテンツ値にわたって使用されます。ここに記載されている内容はすべて docs.croct.com からのものです。記載されていない内容がある場合は、推測せずにライブドキュメント(このファイルの下部)を確認してください。

ワークフロー

  1. クエリが実行される場所を特定します:オーディエンス(ブール値である必要あり)、evaluate/API(任意の JSON 値、最大 500 文字)、または動的値(結果が属性タイプに適合する必要あり、そうでない場合は default)。
  2. データソースを選択します:現在のコンテキスト(page、cart、location、campaign、device)、保存されたプロファイル(user's ...、user's stats)、セッション(session's ...)、または履歴(user has ... イベント式、Scale プラン)。
  3. データが収集されていることを確認します:統合必須 とマークされたもの(プロファイル属性、カート、興味、目標、サインイン状態)は、アプリがそれを送信しない限り決してマッチしません。
  4. 以下のチートシートを使用して記述します。正確なプロパティは context-and-data-types.md で確認してください。
  5. 落とし穴チェックリストを実行し、croct.evaluate() またはダッシュボードの推定ツールでテストします。

チートシート

// 自然なスタイル、技術的なスタイル、混合スタイルはすべて交換可能です
user's score is greater than 90
user.score > 90
user's score > 90
ニーズ構文
プロパティuser's address's city、user's stats' orders、property city of user's address、user.address.city
特殊なキー / インデックスpage.query['coupon-code']、list[0]、(user's interests)[0]
セレクタcart.items[1st]、[:first]、[:last(2)]、items[*].price、data[...].price
リテラルnull、true、42、3.14(小数)、3.14f、51%、"str"、'raw'、~/re/i、[1, 2]、["k": "v"]
日付リテラルなし:"2026-01-01" as date、"2026-01-01T12:00" as datetime; today + 1 day
論理and or not(&& `
比較== != > >= < <=; 1 < x < 3; is equal to X ignoring case
リテラル短縮形X is "value"、X is not 0(右辺はリテラルである必要があります)
文字列starts with、ends with、matches "sub" / matches ~/re/i(大文字小文字区別)、is like "sub"(大文字小文字区別なし)
コレクションcontains X、X is in [..]、contains all of [..]、contains either [..]、contains neither [..]
存在is defined / is known、is empty
ユーザー/セッションuser is returning、user is anonymous、user is identified、session is starting
日付is before、is after、is at "12:00"、is between A and B [exclusive]、today's weekday is "monday"
定量子some x in C satisfies P、every、no、not every、at least 2 of any [distinct] x in C satisfies P
マクロcount of、sum of、average of、min of、max of、first of、last of、keys of、length of、number of days between A and B、this month
修飾子as number、rounded [down]、in title case、sorted descending、without duplicates、replacing "a" with "b"、today at "12:00"
フォールバックuser's name or else "Anonymous"(??)
条件文"A" if cond otherwise "B"、cond ? "A" : "B"
変数let orders = user's stats' orders; orders >= 5
イベント(Scale)user has <event> [with prop value] [at least N times] [in last 7 days]
コメント// line、# line、/* block */

キーワードと識別子は大文字小文字を区別しませんが、文字列リテラルは大文字小文字を区別します。

コンテキスト概要

変数共通プロパティ
userid、firstName、email、age、company、jobTitle、interests、activities、stats' sessions、stats' orders、任意のカスタム属性
sessionstart、duration、landingPage、referrer、stats' pageviews、stats' orders、audiences、experiences、experiments、カスタム属性
page(Web)title、url、path、query、anchor、referrer
locationcontinentCode、countryCode、countryName、stateCode/regionCode(state's code のエイリアス)、stateName、cityName、timeZone、tags
device / browsercategory(desktop、tablet、mobile、bot...)、vendor、name、os; browser's name、type
campaignname、source、medium、content、term(UTM)
cartstage(browsing、shopping、checkout)、items、total、subtotal、coupon、discount
contexttimeZone、評価時に渡される属性
now、today、yesterday、tomorrowweekday、day、month、year、hour...

最も便利なパターン

user is returning
user is not returning
session is starting
device's category is "mobile"
device's category is not "bot"
location's countryCode is "US"
location's state's code is in ["NY", "CA"]
location's cityName is "New York" and today's weekday is "monday"
campaign's source is "google" and campaign's medium is "cpc"
campaign's name matches "sale"
page's path is in ["/pricing", "/plans"]
page's query's newsletter is "daily-news"
page.query['coupon-code'] is defined
session's referrer matches "google"
session's landingPage starts with "https://example.com/promo"
session's duration > 5 minutes and session's stats' orders is 0
user's interests contains either ["marketing", "sales"]
user's age is between 18 and 30
user's stats' orders is 0
user's plan is "premium"
cart's stage is "checkout" and cart's total is greater than 100
some item in cart's items satisfies item's brand is "Apple"
(no item in cart's items satisfies item's name is like "smartphone") and user is returning
user has abandoned a cart at least 2 times
user has viewed a product with category "Shoes" in last 7 days
user has completed goal "demo-requested" last session
user's firstName or else "there"

ユースケース別(キャンペーン、ロケーション、テクノロジー、セッション、プロファイル、カート、注文、値クエリ)の詳細は:references/recipes.md。

コードからの評価

import croct from '@croct/plug';

const isReturning = await croct.evaluate<boolean>('user is returning').catch(() => false);
const inList = await croct.evaluate<boolean>(
  "context's countries include location's countryName",
  {attributes: {countries: ['United States', 'Canada']}}, // `context's countries` として読み取られます
);

Next.js サーバー: @croct/plug-next/server から await evaluate(query) または await cql`user's persona is in ${roles}` 。React: useEvaluation(query)。HTTP: POST https://api.croct.io/client/web/evaluate、リクエストボディ {"query": "..."}。詳細、属性制限、動的値、推定:references/evaluation.md。

落とし穴とデバッグ

症状考えられる原因修正
x is y で構文エラーis 短縮形は右辺にリテラルが必要x is equal to y または x == y
location city is "Berlin" で構文エラーアクセサなし:変数とそのプロパティの間に裸の単語があるlocation's cityName、property cityName of location、または location.cityName
"1" > 0 または session's start > "2026-01-01" の比較エラー関係演算子は型を変換しないキャスト:"1" as number > 0、... > "2026-01-01" as datetime、または is after を使用
ロケーション/コードが決してマッチしない大文字小文字の誤り:コードは大文字("US"、"NA"、"CA")で、文字列は大文字小文字を区別する大文字を使用、is like、is equal to ... ignoring case、または ~/.../i を使用
matches "Sale" が "sale" にマッチしないmatches、starts with、ends with は大文字小文字を区別するis like "sale" または matches ~/sale/i
定量子が後続の条件を飲み込む定量子の述語は最後まで拡張される定量子全体を括弧で囲む
a or b and c が奇妙に動作するand は or よりも強く結合する括弧を追加
条件付き結果が誤って乗算される条件文は貪欲である(A if c otherwise B) * price
プロファイル/カート/興味の条件が真にならない統合必須データが送信されていないイベントを追跡するか、属性を設定します(croct-track-events スキルを参照)
X is greater than 30 と X is not greater than 30 の両方が偽未定義値:ブールエラー耐性により偽になるX is defined and ... または X or else 0 を使用
user is identified が常に偽サインイン/アップ/アウトイベントが追跡されていないそれらを追跡する。そうしないとユーザーは常に匿名となる
cart.items[2nd]、first of、average of、min of エラー要素がないか、コレクションが空or else null / or else 0 を追加
contains none of [] vs contains neither []空の右辺:none は偽、neither は真重複なしには contains neither を使用
's と括弧の混在エラー所有権/属格と括弧には括弧が必要(cart's items)[1st] またはドット記法 cart.items[*]
イベント式が利用不可Scale プランの機能可能な場合はプロファイル/セッション統計を使用する(user's stats' orders)
「推定不可」page、現在のコンテキスト、または now/today/yesterday を使用している想定内。オーディエンスは実行時には機能する
範囲エラー.. 範囲は最大 30 項目範囲を狭める
変数/パラメータ名エラー変数は再定義不可。名前は識別子である必要がある名前を変更する。組み込み名(user、page)や一般的な単語は避ける

推奨事項:

  • 非開発者と共有するオーディエンスでは、明示的な is equal to、is greater than を優先する。読みやすい場合は技術スタイルを使用する。
  • オプショナルデータは is defined または or else で保護する。
  • and チェーンでは安価な条件を最初に配置する(短絡評価により残りをスキップ)。
  • contains all / contains none を否定する代わりに、contains either / contains neither を使用する。

禁止事項:

  • テスト、変数、イベント表現を発明しないこと。user is new や user has made purchase などの例はドキュメントの散文に登場しますが、文書化された構造ではありません。user is not returning や user's stats' orders is not 0(または user has placed an order)を使用してください。
  • location's countryName をコードと比較しないこと。"US" には countryCode を使用してください。
  • 算術演算での暗黙の日付変換に依存しないこと:"2021-01-01" as date + 1 day。

参考文献

ファイル読むタイミング
references/syntax.md字句規則、let、関数、リテラル、アクセサとセレクタ、優先順位テーブル、条件文、期間
references/context-and-data-types.mdすべての変数とプロパティ、利用可能性フラグ、列挙型(デバイスカテゴリ、カートステージ、大陸、ロケーションタグ)、変換
references/expressions.mdすべてのテスト、演算子、エラー耐性、定量子、マクロ、修飾子
references/events.mdイベント式、条件演算子、カウント定量子、時間枠、追跡要件
references/evaluation.mdSDK evaluate / cql / フック、Evaluation API、コンテキスト属性、動的値、オーディエンス推定
references/recipes.mdユースケース別のすぐに使えるオーディエンスと値クエリ

関連スキル:croct-integrate-sdk(SDK セットアップ)、croct-track-events(クエリが読み取るイベントと属性の送信)、croct-use-api(HTTP API)、croct-model-content(コンテンツ定義内の動的値)、croct-personalize-and-test(オーディエンスを使用するエクスペリエンスと実験)、croct-use-croct(概念とオリエンテーション)。

ライブドキュメント

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

croct-tech/agent-skills

>- Use when connecting Croct to a third-party platform or migrating to Croct from another personalization or experimentation tool. Covers Storyblok (Optimize by Croct app, @croct/plug-storyblok, Storyblok withCroct, resolveContent, croct/plug-storyblok, CroctStoriesApi), Sanity and Strapi (slot fallback, dynamic zones, metadata.contentSource), Shopify Hydrogen storefront events, Shopify custom pixel (croctPixel, PUBLIC_CROCT_SHOPIFY_PIXEL, checkout and order tracking), VTEX, Google Tag Manager data layer, Microsoft Clarity tags, HubSpot forms (hbspt.forms.create, hs-form-event), firmographic providers 6sense, Demandbase, Clearbit Reveal, and ZoomInfo WebSights (firmographics attributes, account-based audiences in CQL), and migrations from Mutiny and Ninetailed (Experience component, Contentful sunset). Triggers include cdn.croct.io/plug-integration scripts, "personalize Storyblok blocks", "track Shopify checkout", "send VTEX events", "ABM personalization", "replace Mutiny".

croct-tech/agent-skills

>- Use when installing or using a Croct SDK in application code: rendering slot content, evaluating CQL queries, server or client fetching, prerendering, identifying users, app ID / API key env vars, testing, or debugging. Covers JavaScript (`@croct/plug`, `croct.fetch`, `croct.evaluate`), React (`@croct/plug-react`, `<CroctProvider>`, `useContent`, `<Slot>`, `useEvaluation`, `useCroct`), Next.js (`@croct/plug-next`, `fetchContent`, `cql`, middleware/proxy, `NEXT_PUBLIC_CROCT_APP_ID`, `CROCT_API_KEY`), Vue (`@croct/plug-vue`), Nuxt (`@croct/plug-nuxt`), Shopify Hydrogen (`@croct/plug-hydrogen`), PHP (`croct/plug-php`), Laravel, Symfony, and Drupal. Triggers: slot IDs like `home-hero@1`, `SlotContent`, "Croct is not plugged in", "initial content is required for server-side rendering", "Did you forget to configure Croct's middleware?", CORS errors.

croct-tech/agent-skills

>- Use when designing or changing Croct content models: regular vs union components, what becomes a component, slot, structure, or primitive attribute; writing component schema JSON (`structure`, `union`, `reference`, `text`, `number`, `boolean`, `list`, `@croct/file`, `@croct/richText` rich text, `format`, `choices`, `optional`, `private`, `position`); writing content definition JSON (`static`/`dynamic` values, `nullable`, `default`, `{{placeholder}}` paths); slot default, localized, experience, experiment, or content group content; schema limit errors (30 attributes, 6 nesting levels, 10 union members, complexity score 50); component versioning and breaking changes (`home-hero@2`); refactoring (duplicate and modify, duplicate and replace, flatten and merge); Markdown in text attributes with `@croct/md-lite`. Phrasings: "model content for a hero", "add an attribute to the banner component", "support variations", "component is too complex", "localize the hero", "translations", `preferredLocale`.

croct-tech/agent-skills

>- Use when planning or implementing personalization or A/B testing with Croct: creating an experience (audience, slots, content, priority, scheduling, drafts), adding an experiment (A/B/n, primary goal ID, traffic allocation, variants, cross-device consistency), wiring the code it needs (slots, `croct.track('goalCompleted', {goalId})`, `orderPlaced`, `leadGenerated`, `userSignedUp`), server-side feature-flag experiments, redirect experiments, personalization recipes (UTM campaigns, ABM, search terms, location, free shipping, interests, blog readers, leads, customers, organic intent, HubSpot forms), or reading the experience, experiment, application, or workspace dashboards (probability to be best, potential loss, "Experiment in progress", "Recommended winner", "No clear winner", "Track your goal"). Phrasings: "personalize the hero for LinkedIn visitors", "A/B test this CTA", "which variant won?", "why does my experiment show no conversions?".

関連スキル