Option 1: Implement context using code

Grab the code from the General Settings screen and paste the relevant code on each page.

Here are some code examples.

Using hooks in SPAs

/**
* @param {string} type
* @param {string[]} data
*/
export function setDYContext(type, data) {
  window.DY = window.DY || {};
  DY.recommendationContext = { type: type, data: data };
}     
      
export default function HomePage() {
  // ...
  useEffect(() => setDYContext('HOMEPAGE'));
  return (
  // ...
  )
} 
/**
* @param {string} type
* @param {string[]} data
*/
export function setDYContext(type, data) {
  window.DY = window.DY || {};
  DY.recommendationContext = { type: type, data: data };
}          

export default function ProductPage(props) {
  // ...
  useEffect(() => setDYContext('PRODUCT', [ props.sku ]), [ props.sku ]);
  
  return (
  // ...
  )
}

Using lifecycle methods in SPAs

/**
* @param {string} type
* @param {string[]} data
*/
export function setDYContext(type, data) {
  window.DY = window.DY || {};
  DY.recommendationContext = { type: type, data: data };
}

export default class HomePage extends React.Component{
  // ...
  
  componentDidMount() {
    setDYContext('HOMEPAGE');
  }
  
  render() {
    return(
      // ...
    )
  }
}
/**
* @param {string} type
* @param {string[]} data
*/
export function setDYContext(type, data) {
  window.DY = window.DY || {};
  DY.recommendationContext = { type: type, data: data };
}

export default class ProductPage extends React.Component{
  constructor(props) {
    super(props);
    this.state = { sku: props.sku }
    }
    // ...
  
  componentDidMount() {
    setDYContext('PRODUCT', [ this.props.sku ]);
  }
  
  componentDidUpdate(prevProps) {
    if (prevProps.sku !== this.props.sku) {
      setDYContext('PRODUCT', [ this.props.sku ]);
    }
  }
  render() {
    return(
      // ...
    )
  }
}

Example: Product page context (e-commerce and financial institutions)

<script type="text/javascript">
  window.DY = window.DY || {}; 
  DY.recommendationContext = { type: "PRODUCT", data: ['SKU123'] }; // in this example - a product page 
</script>

Example: Post page (media)

<script type="text/javascript">
  window.DY = window.DY || {}; 
  DY.recommendationContext = { type: "POST", data: ['POST_ID123'] }; // in this example - a post page 
</script>