Appearance
Audiences
You can use Almeta ML model calculations to create audiences on Google Ads, Meta Ads, Bing Ads, and other advertising networks.
Concepts
Any ML model calculation that's triggered by a web tag or an event trigger sends a browser event with the results of the calculation:
javascript
window.addEventListener('almeta_calculation_result', (event) => {
console.log('Model calculation result:', event.detail);
})
You can listen to this event in your website's JavaScript code, and trigger the tracking of any advertising network from the callback function. For example, you can predict the likelihood of a purchase by the user, and trigger different tracking events for different results:
javascript
window.addEventListener('almeta_calculation_result', function(event) {
if (!event.detail || event.detail.status != 'ok')
return;
if (event.detail.model_id == 'YOUR_MODEL_ID')
{
// Send the model output to a custom Meta Ads event
fbq('trackCustom', 'almeta_purchase_prob_score', {
score: event.detail.output
});
}
});
This code does the following:
- Listens for the
almeta_calculation_result
browser event. - Checks if the calculation result is successful.
- Checks if the calculation result is for the model you want to track.
- Sends the model output to a custom Meta Ads event.
You can use the almeta_purchase_prob_score
event in Meta Ads to create an audience of people with a certain probability of making a purchase, and adjust your ad spend and targeting accordingly.
This works with any other network that supports custom events, such as Google Ads, Bing Ads, and others.
Setting Up Audiences with Google Tag Manager
This tutorial shows how to segment your website users by likelihood to purchase and send these audiences to Meta Ads and Google Ads for retargeting.
Prerequisites
For this tutorial, you need to have an active propensity model in Almeta ML, and a Google Tag Manager account. Please refer to Web Tag Installation for more information on how to install the web tag. You will also need accounts with the advertising networks you want to use: Meta Ads, Google Analytics / Google Ads, etc.
Variables
Let's start by creating variables in Google Tag Manager that will store the ID of the model we want to use, as well as the output of the model calculation.
- Create a new variable in Google Tag Manager and name it
almetaPropensityToPurchaseModelId
, select variable type Constant, and set the value to the ID of the propensity to purchase model you want to use. - Create a new variable in Google Tag Manager and name it
Almeta Propensity to Purchase Score
, select variable type Data Layer Variable, and set its Data Layer Variable Name topropensityToPurchaseScore
. This variable will store the output of the propensity to purchase model calculation as a number. - Create a new variable in Google Tag Manager and name it
Almeta Propensity to Purchase Group
, select variable type Data Layer Variable, and set its Data Layer Variable Name topropensityToPurchaseGroup
. We will use this variable to group users into Low, Medium, and High likelihood to purchase groups.
Triggers
Next, we will create triggers in Google Tag Manager to simmplify creating tags for multiple advertising platforms that will get triggered based on the propensity to purchase model calculation.
- Create a new trigger in Google Tag Manager and name it
Almeta - Propensity to Purchase Calculation
, select trigger type Custom Event, and set its Custom Event Name topropensity_to_purchase_calculation
. - Create a new trigger in Google Tag Manager and name it
Almeta - Propensity to Purchase Group Calculation
, select trigger type Custom Event, and set its Custom Event Name topropensity_to_purchase_group_calculation
.
We will call custom data layer events to run these triggers when the calculation results are received.
Tags
Finally, we will create tags that will check the calculation results, store them in the variables we created earlier, and trigger the tags for the different advertising platforms.
- Create a new tag in Google Tag Manager and name it
Almeta Propensity to Purchase Calculation
, select tag type Custom HTML, and set its HTML to the following code:
html
<script>
window.addEventListener('almeta_calculation_result', function(event) {
if (!event.detail || event.detail.status != 'ok')
return;
// Check if the calculation result is for the model we want to track
if (event.detail.model_id == '{{almetaPropensityToPurchaseModelId}}')
{
// Push the calculation result to the data layer
// to run the triggers that we created earlier
window.dataLayer.push({
'event': 'propensity_to_purchase_calculation',
'result': event.detail,
});
// Set the value of the propensity to purchase group variable
var propensity_to_purchase_group = 'unknown';
if (event.detail.output < 0.1)
propensity_to_purchase_group = 'low'
else if (event.detail.output < 0.3)
propensity_to_purchase_group = 'medium';
else if (event.detail.output >= 0.3)
propensity_to_purchase_group = 'high';
// Push the propensity to purchase group calculation result to the data layer
window.dataLayer.push({
'event': 'propensity_to_purchase_group_calculation',
'group': propensity_to_purchase_group,
});
// Set the propensity to purchase score variable
dataLayer.push({'propensityToPurchaseScore': event.detail.output});
// Set the propensity to purchase group variable
dataLayer.push({'propensityToPurchaseGroup': propensity_to_purchase_group});
}
});
</script>
In this example, we are using the 'low' group to target people with a likelihood to purchase score below 10%, the 'medium' group to target people with a propensity to purchase score between 10% and 30%, and the 'high' group to target people with a propensity to purchase score above 30%. You can adjust these thresholds to match your business needs.
Set the trigger of this tag to Page View, so that it runs on page load. When a calculation result is received, the tag will run and send the propensity to purchase group and propensity to purchase score to the data layer.
- Create a new tag in Google Tag Manager and name it
Meta / Facebook - Almeta Propensity to Purchase
, select tag type Custom HTML, and set its HTML to the following code:
html
<script>
if (typeof fbq == 'function')
{
fbq('trackCustom', 'almeta_purchase_prob_group', { group: '{{Almeta Propensity to Purchase Group}}' });
fbq('trackCustom', 'almeta_purchase_prob_score', { score: '{{Almeta Propensity to Purchase Score}}' });
}
</script>
Set the trigger of this tag to Almeta - Propensity to Purchase Calculation, so that it runs when the propensity to purchase group calculation result is received. When a calculation result is received, the tag will run and send the propensity to purchase score and group to Meta Ads.
- For Google Ads you can also use a Custom HTML tag, but it's easier to choose the built-in GA4 Event tag type. Create a new tag in Google Tag Manager and name it
Google - Almeta Propensity to Purchase
, select tag type Google Analytics: GA4 Event, select your measurement ID, and set its Event Name topropensity_to_purchase_calculation
.
Then choose the event parameters you want to send to Google Ads, for example:
propensity_to_purchase_group: {{Almeta Propensity to Purchase Group}}
propensity_to_purchase_score: {{Almeta Propensity to Purchase Score}}
You can also set the user properties, similar to event parameters, for example:
propensity_to_purchase: {{Almeta Propensity to Purchase Score}}
prop_to_purchase_group: {{Almeta Propensity to Purchase Group}}
Set the trigger of this tag to Almeta - Propensity to Purchase Calculation, so that it runs when the propensity to purchase group calculation result is received. When a calculation result is received, the tag will run and send the propensity to purchase score and group to Google Analytics, which also enables its use in Google Ads.
Creating Audiences in Advertising Platforms
Once you set up and publish the tags in Google Tag Manager, you can create audiences in your advertising platforms based on the propensity to purchase score and group.
For example, you can create audiences in Google Analytics for your reference, and use them in Google Ads for targeting. To do this in GA4, go to Admin (at the bottom of the left sidebar) > Audiences > New Audience, and set the following parameters:
Parameter | Value |
---|---|
Audience Name | Almeta: High Likelihood to Purchase |
Include users when: | Propensity to Purchase Group exactly matches high |
This will create a new audience that will only contain users with a high likelihood to make a purchase, as predicted by Almeta ML. You can repeat this process to create audiences with likelihood to make a purchase matching medium
and low
.
Conclusion
This guide shows an example setup for a model that predicts the likelihood to make a purchase on your website. You can use similar setups for other types of predictions.
If you need help setting up Almeta ML on your website for real-time predictions, you can schedule an expert installation with us. It includes setting up Almeta ML web tag, tracking all events that are relevant for your website, getting machine-learning models up and running, and processing real-time predictive metrics on your site to use in marketing audiences.