Skip to content

Web Tags and Models

You can query machine learning models, metrics and calculations directly from web tags.

Run a model from web tag

You can get the results of a model calculation by calling the calculate function in the web tag. You will need the model ID to run the model. The result of the calculation will be sent to the almeta_calculation_result browser event.

  1. Create a model in the Almeta Cloud console to get a model ID.
  2. Include a web tag in the <head> section of your website's HTML.
  3. Register an event listener to get the results:
javascript
window.addEventListener('almeta_calculation_result', (event) => {
    console.log('Model calculation result:', event.detail);
})
  1. Call the calculate function of the web tag in javascript:
javascript
_almeta.t('calculate', {
    model_id: MODEL_ID, // replace with your model ID
});

This will trigger the calculation of the model for the current website user and send the result to the almeta_calculation_result browser event.

You can also await the result of the calculation:

javascript
const result = await _almeta.calculate({
    model_id: MODEL_ID, // replace with your model ID
});

This will return the result of the calculation as a JavaScript object.