JavaScript

Install the Coframe SDK on any website with a script tag

Guide~3 min read

Copy this guide and your current settings as a prompt for your AI agent.

Preview agent promptSee the guide, code and settings included when you copy.

This guide is for any site where you can directly edit the HTML — a static site, a CMS with a custom code block, a hand-rolled landing page, or any other environment where you control the markup. If you are using a framework such as Next.js or React, see the framework-specific guide for your environment. If you are using Webflow, see the Webflow guide.

Watch: 65s — installing the script tag in the <head>, setting your project ID, and verifying in DevTools
On this page
  1. 01Where to install
  2. 02Installation script
  3. 03Verify it is working
  4. 04Optional configuration

01Where to install

Place the installation script in the <head> of every page you want Coframe to optimize or track. The script must be added directly to the HTML — do not load it through an async tag manager (such as Google Tag Manager). Because anti-flicker is enabled, the script needs to run synchronously before the browser renders the page body. Loading it asynchronously through a tag manager defeats this and will cause a visible flash of unstyled content.

If your site has a shared layout or template that renders the <head>, that is the right place to add the script so it appears on every relevant page automatically.

Configure your installation

Set your project ID and options in the editor. Then follow the steps below using the updated code.

Installation editor

Configure once. Every code snippet in the guide updates with your settings.

Use your public project ID, or replace the placeholder before publishing.
Main Installation Script

Add this script to the <head> of your page. Must be installed synchronously (not via tag managers) because antiflicker is enabled.

HTML · generated from your settings
<script id='coframe-installation-script'>
  (function () {
    // Early exit for performance testing
    if (/cf_disable/.test(location.search)) return console.warn('[Coframe] Disabled via URL parameter');
  
    // Coframe config
    const config = {
      projectId: 'YOUR_PROJECT_ID',
      startTime: Date.now(),
      timeoutMs: 1000,
      currentUrl: window.location.href,
    };
  
    // Prevent duplicate installation
    const script_id = 'coframe-sdk-js';
    if (document.getElementById(script_id)) return console.warn('[Coframe] SDK already installed');
  
    // Coframe queue setup
    (window.CFQ = window.CFQ || []).push({ config });
  
    // Coframe antiflicker CSS
    const style = document.createElement('style');
    style.id = 'coframe-antiflicker';
    style.textContent =
      ':root { --cf-show: 0;}' +
      'body { opacity: var(--cf-show) !important; transition: opacity 0.2s ease; }'
    function hide() { document.head.appendChild(style); }
    function show() {
      document.documentElement.style.setProperty('--cf-show', '1');
      style.parentNode && style.parentNode.removeChild(style);
    }
    hide(); setTimeout(show, config.timeoutMs);
  
    // Coframe SDK JS
    var edgeUrl = new URL('https://edge.cofra.me/cf.js');
    edgeUrl.searchParams.set('config', encodeURIComponent(JSON.stringify(config)));
  
    const script = document.createElement('script');
    script.id = script_id;
    script.async = true;
    script.src = edgeUrl.toString();
    script.onerror = () => { show(); console.error('[Coframe] SDK failed to load'); };
    document.head.appendChild(script);
  })();
</script>
1 script · 0 companions
Configuration1 on
Antiflicker mode

02Installation script

Copy the script below and paste it into the <head> of your page. Replace YOUR_PROJECT_ID with the project ID from your Coframe dashboard.

HTML
<script id='coframe-installation-script'>
  (function () {
    // Early exit for performance testing
    if (/cf_disable/.test(location.search)) return console.warn('[Coframe] Disabled via URL parameter');
  
    // Coframe config
    const config = {
      projectId: 'YOUR_PROJECT_ID',
      startTime: Date.now(),
      timeoutMs: 1000,
      currentUrl: window.location.href,
    };
  
    // Prevent duplicate installation
    const script_id = 'coframe-sdk-js';
    if (document.getElementById(script_id)) return console.warn('[Coframe] SDK already installed');
  
    // Coframe queue setup
    (window.CFQ = window.CFQ || []).push({ config });
  
    // Coframe antiflicker CSS
    const style = document.createElement('style');
    style.id = 'coframe-antiflicker';
    style.textContent =
      ':root { --cf-show: 0;}' +
      'body { opacity: var(--cf-show) !important; transition: opacity 0.2s ease; }'
    function hide() { document.head.appendChild(style); }
    function show() {
      document.documentElement.style.setProperty('--cf-show', '1');
      style.parentNode && style.parentNode.removeChild(style);
    }
    hide(); setTimeout(show, config.timeoutMs);
  
    // Coframe SDK JS
    var edgeUrl = new URL('https://edge.cofra.me/cf.js');
    edgeUrl.searchParams.set('config', encodeURIComponent(JSON.stringify(config)));
  
    const script = document.createElement('script');
    script.id = script_id;
    script.async = true;
    script.src = edgeUrl.toString();
    script.onerror = () => { show(); console.error('[Coframe] SDK failed to load'); };
    document.head.appendChild(script);
  })();
</script>

03Verify it is working

After adding the script and loading the page in a browser:

  • Open the browser console and confirm there are no [Coframe] error messages.
  • In the Network tab, look for a request to edge.cofra.me/cf.js. A successful 200 response means the SDK loaded correctly.
  • Check that a coframe-sdk-js script element appears in the DOM (you can inspect the <head> in the Elements panel).

For a full walkthrough of how to validate the integration and confirm that Coframe is operating as expected, see Testing and Validation.

04Optional configuration

The default script is designed to work without additional configuration. Once the SDK is installed, you can tune behavior using the following guides:

  • SDK options — timeout, disable conditions, and other core settings
  • Identity settings — associate SDK activity with a known user identity
  • Tracking settings — control which events and page interactions Coframe records
  • Anti-flicker — understand how the anti-flicker mechanism works and how to adjust it for your performance requirements

Related reading

Content and video lessons from Coframe documentation. Code examples are not executed on this page.

BACK TOSDK Integrations

Documentation

Open Coframe App

Search documentation

Search all guides and references↑ ↓ Navigate · Esc Close