Termly provides three ways to embed a policy on your React website. 


Your options include:

  • HTML format: Pasting static HTML directly to your website
  • URL: Linking to a Termly-hosted URL (available for Pro+ users)
  • Code snippet: Embedding the policy on your page using a code snippet (available for Pro+ users)


Code snippet


To embed a Termly policy using the code snippet option on a React page, you can use the useEffect hook and the createElement function from the react package to create a script element and add it to the page. 


With the example below, we create a new functional component, ‘Policy’.


Simply change the value of data-id to the data-id listed in the code snippet that you export from Termly.


import React, { useEffect } from "react";

export default function Policy() {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://app.termly.io/embed-policy.min.js";
    script.async = true;
    document.body.appendChild(script);
  }, []);

  return (
    <div
      name="termly-embed"
      data-id="43904e5f-c5ed-4170-800a-74e5246a8675"
      data-type="iframe"
    ></div>
  );
}