Randomizing campaigns by entity to ensure equal exposure.
This commit is contained in:
parent
5291b11c1f
commit
25ce0fe1ec
|
@ -340,6 +340,7 @@ function updateFilter(prop, value, reload = true) {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
margin-bottom: .5rem;
|
margin-bottom: .5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,12 +57,28 @@ export async function getRandomCampaign(options = {}, context = {}) {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
const primaryCampaigns = validCampaigns.filter((campaign) => campaign.entity.id === options.entityIds?.[0]);
|
const campaignsByEntityId = validCampaigns.reduce((acc, campaign) => {
|
||||||
|
const entityId = campaign.entity.parent?.id || campaign.entity.id;
|
||||||
|
|
||||||
|
if (!acc[entityId]) {
|
||||||
|
acc[entityId] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
acc[entityId].push(campaign);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// randomize entities first to ensure fair exposure for entities with fewer banners
|
||||||
|
const entityIds = Object.keys(campaignsByEntityId);
|
||||||
|
const randomEntityCampaigns = campaignsByEntityId[entityIds[crypto.randomInt(entityIds.length)]];
|
||||||
|
|
||||||
|
const primaryCampaigns = randomEntityCampaigns.filter((campaign) => campaign.entity.id === options.entityIds?.[0]);
|
||||||
|
|
||||||
if (validCampaigns.length > 0) {
|
if (validCampaigns.length > 0) {
|
||||||
const randomCampaign = primaryCampaigns.length > 0
|
const randomCampaign = (primaryCampaigns.length > 0 ? primaryCampaigns[crypto.randomInt(primaryCampaigns.length)] : null)
|
||||||
? primaryCampaigns[crypto.randomInt(primaryCampaigns.length)]
|
|| (randomEntityCampaigns.length > 0 ? randomEntityCampaigns[crypto.randomInt(randomEntityCampaigns.length)] : null)
|
||||||
: validCampaigns[crypto.randomInt(validCampaigns.length)];
|
|| validCampaigns[crypto.randomInt(validCampaigns.length)];
|
||||||
|
|
||||||
return randomCampaign;
|
return randomCampaign;
|
||||||
}
|
}
|
||||||
|
|
2
static
2
static
|
@ -1 +1 @@
|
||||||
Subproject commit 6289c5ff5707aac96d306f29805c322393164d3a
|
Subproject commit 76242feb7b3e75bcc581d9b19ee509c6e01a87aa
|
Loading…
Reference in New Issue