https://metaplay.io logo
OfferPerPlayer ActivationFinalized does not contai...
# questions-and-feedback
d
There is no way to know from within MetaOfferPerPlayerStateBase derived class to know what offer got its activation Finalized, No offerInfo no offer ID even is passed to the finalization. Only way to pass any other information would be to override the and pass offerId to the custom OnActivationFinalized
Copy code
protected override void OnFinalizedActivation(MetaOfferGroupId groupId, IPlayerModelBase player)
        {
            MetaOfferGroupModelBase group = TryGetState(groupId);

            foreach ((MetaOfferId offerId, MetaOfferPerGroupStateBase offerPerGroup) in group.OfferStates)
            {
                if (offerPerGroup.IsIncludedInGroupActivation(group.CurrentActivationIndex))
                {
                    if (OfferStates.TryGetValue(offerId, out MetaOfferPerPlayerStateBase offerPerPlayer))
                        offerPerPlayer.OnActivationFinalized(player, group.LatestActivation.Value.EndAt.Value);
                }
            }
        }
of PlayerMetaOfferGroupsModelBase and cast
offerPerPlayer
to derived per player state type. or am I missing something?
n
Hi, i think you're right and not missing anything. Can you elaborate on what the goal is? Maybe there's another way to achieve it, or if not, maybe it makes sense to add the offerInfo parameter to the SDK's MetaOfferPerPlayerStateBase.OnActivationFinalized.
d
the original usecase was for us to trigger analytics event when offer is activated or deactivated - since the activation happens in the SDK code and not always is in client code controll this seamed as the best place for it
n
Alright, makes sense. Ideally the SDK would indeed provide a direct way of doing this. As is, without SDK modification, the simplest way might be to override
PlayerMetaOfferGroupsModelBase<...>.OnFinalizedActivation
similarly to how you describe. However, i don't think it's necessary for this custom code to involve the MetaOfferPerPlayerState (unless it actually needs some data from there) but just do things directly in the
PlayerMetaOfferGroupsModelBase
override. Maybe something along these lines:
Copy code
protected override void OnFinalizedActivation(MetaOfferGroupId groupId, IPlayerModelBase player)
{
    base.OnFinalizedActivation(groupId, player);

    MetaOfferGroupModelBase group = TryGetState(groupId);

    foreach ((MetaOfferId offerId, MetaOfferPerGroupStateBase offerPerGroup) in group.OfferStates)
    {
        if (offerPerGroup.IsIncludedInGroupActivation(group.CurrentActivationIndex))
            OnFinalizedOfferActivation(groupId, offerId, player);
    }
}

void OnFinalizedOfferActivation(MetaOfferGroupId groupId, MetaOfferId offerId, IPlayerModelBase player)
{
    if (!player.GameConfig.MetaOfferGroups.TryGetValue(groupId, out MetaOfferGroupInfoBase groupInfo))
        return; // unexpected, but tolerate
    if (!player.GameConfig.MetaOffers.TryGetValue(offerId, out MetaOfferInfoBase offerInfo))
        return; // unexpected, but tolerate

    // ... trigger analytics event ...
}