{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Guides","type":"markdown"},"seo":{"title":"Integrate using Cloudflare Workers","description":"Everything about Mosaic Journeys, SDKs, and APIs","siteUrl":"https://developer.transmitsecurity.com/","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"integrate-using-cloudflare-workers","__idx":0},"children":["Integrate using Cloudflare Workers"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes how to use Cloudflare Workers to integrate Agent Intelligence into your web app. For more information about Cloudflare Workers, see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.cloudflare.com/workers/"},"children":["Cloudflare's documentation"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A Mosaic application with client credentials. Create an application in the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://portal.transmitsecurity.io/"},"children":["Admin Portal"]}," if you do not already have one."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Your web application must already be integrated with Cloudflare Workers."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-1-load-sdk-via-cloudflare-worker","__idx":2},"children":["Step 1: Load SDK via Cloudflare Worker"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Load and initialize the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/sdk-ref/platform/introduction/"},"children":["Platform SDK"]}," using Cloudflare Workers:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Log in to your Cloudflare dashboard and go to ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Workers"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Create or update an existing Worker, and make sure the Worker's routes are defined for all relevant application pages. See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.cloudflare.com/workers/platform/triggers/routes/#background"},"children":["Routes"]}," for information about adding routes to Cloudflare Workers."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["On the Worker page, click ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Quick edit"]}," and add the code below to the JavaScript code pane on the left. Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<CLIENT_ID>"]}," with the client ID of your app (can be found in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://portal.transmitsecurity.io/"},"children":["Admin Portal"]},") and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<SERVER_PATH>"]}," with the endpoint for your region or custom domain."]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["agenticCollect: true"]}," in the SDK configuration to enable Agent Intelligence detection."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you already use Mosaic Fraud Prevention, make sure the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["clientId"]}," and the region in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["serverPath"]}," match the ones configured for your existing integration."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"js","header":{"controls":{"copy":{}}},"source":"const AGENTIC_CLIENT_ID = '<CLIENT_ID>'; // Client ID of your app\nconst AGENTIC_SERVER_PATH = '<SERVER_PATH>'; // e.g. Set to https://api.transmitsecurity.io/risk-collect/ or other depending on your region or custom domain\nconst PLATFORM_SDK_URL = 'https://platform-websdk.transmitsecurity.io/platform-websdk/2.x/ts-platform-websdk.js';\n\nconst AGENTIC_SNIPPET = `\n<script src=\"${PLATFORM_SDK_URL}\" id=\"ts-agentic-loader\" data-ts-agentic-self></script>\n<script data-ts-agentic-self>\n  (function () {\n    if (window.__agenticSdkInit) return;\n    window.__agenticSdkInit = true;\n    var s = document.getElementById('ts-agentic-loader');\n    if (!s) return;\n    function go() {\n      if (window.__agenticSdkStarted) return;\n      if (!window.tsPlatform || typeof window.tsPlatform.initialize !== 'function') return;\n      window.__agenticSdkStarted = true;\n      try {\n        window.tsPlatform.initialize({\n          clientId: '${AGENTIC_CLIENT_ID}',\n          drs: {\n            serverPath: '${AGENTIC_SERVER_PATH}',\n            agenticCollect: true\n          }\n        });\n      } catch (e) { /* never break the page */ }\n    }\n    if (window.tsPlatform && window.tsPlatform.initialize) go();\n    else s.addEventListener('load', go);\n  })();\n</script>\n`;\n\nexport default {\n  async fetch(request) {\n    const response = await fetch(request);\n\n    const contentType = response.headers.get('content-type') || '';\n    if (!contentType.includes('text/html')) {\n      return response; // pass through anything non HTML\n    }\n\n    return new HTMLRewriter().on('body', new AgenticInjector()).transform(response);\n  },\n};\n\nclass AgenticInjector {\n  element(element) {\n    element.onEndTag((endTag) => {\n      endTag.before(AGENTIC_SNIPPET, { html: true });\n    });\n  }\n}\n","lang":"js"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-2-validate-in-mosaic","__idx":3},"children":["Step 2: Validate in Mosaic"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["After you deploy the Worker and drive traffic through the covered routes, open ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Agent Intelligence"]}," in Mosaic and start with ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Sessions"]},"."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Confirm that session records begin appearing for the applications and routes covered by your integration."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Review fields such as ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Activity Surface"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Start Time"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Agent Platform"]},", and ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Origin Type"]}," to verify that the expected traffic is being collected."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Open individual sessions to inspect additional details such as ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["IP Address"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Country"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["OS"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Browser"]},", and path data when available."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If data doesn't appear, verify the following:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The Worker routes include the relevant HTML pages"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The Platform SDK script is being injected into the page source"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["serverPath"]}," matches the correct region or your custom domain"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Your CSP allows the Platform SDK script and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["risk-collect"]}," endpoint. See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/quick_start/enable_communication/"},"children":["Enable API communication"]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["First agent platforms typically surface within hours of activation. Agentic traffic volume builds gradually over the first several weeks—check trends across multiple weeks rather than a single day."]}]}]},"headings":[{"value":"Integrate using Cloudflare Workers","id":"integrate-using-cloudflare-workers","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Step 1: Load SDK via Cloudflare Worker","id":"step-1-load-sdk-via-cloudflare-worker","depth":2},{"value":"Step 2: Validate in Mosaic","id":"step-2-validate-in-mosaic","depth":2}],"frontmatter":{"title":"Integrate using Cloudflare Workers","markdown":{"toc":{"depth":2}},"seo":{"title":"Integrate using Cloudflare Workers"}},"lastModified":"2026-08-19T14:36:48.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/agent-intelligence/integrate_cloudflare","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}