Variation Applied

Variation Applied

Overview

The onVariationApplied callback is triggered when a campaign is applied to the page. This callback provides access to the experiment and variation details, allowing for custom functionality based on the variation a visitor is exposed to. Always check if the data parameter exists before accessing its properties.

Signature

window.Wingify = window.Wingify || [];
window.Wingify.push(['onVariationApplied', function (data) {
    // Callback logic here
}]);

Arguments

ParameterData TypeRequiredDescription
callback_functionFunctionYesThe callback function executes when a campaign runs.

Callback Data

The callback function receives a single data object that contains information about the visitor, the applied campaign, and the assigned variation.

Type

PropertyTypeDescription
visIdstringUnique identifier of the visitor.
campTypestringType of the applied campaign. Possible values include VISUAL_AB, VISUAL, and SPLIT_URL.
campIdstringUnique identifier of the applied campaign.
campNamestringName of the applied campaign.
varIdstringUnique identifier of the variation assigned to the visitor.
varNamestringName of the variation assigned to the visitor.
targetIdstring | nullUnique identifier of the target. Available only for Personalize campaigns; otherwise null.
targetNamestring | nullName of the target. Available only for Personalize campaigns; otherwise null.

Example

window.Wingify = window.Wingify || [];
window.Wingify.push(['onVariationApplied', function (data) {
    if (!data || !data.campId) return;

    var visitorIdentity = data.visId;
    var campaignType = data.campType;
    var campaignIdentity = data.campId;
    var campaignName = data.campName;
    var variationIdentity = data.varId;
    var variationName = data.varName;
    var targetIdentity = data.targetId;   // null unless Personalize holdback
    var targetName = data.targetName;   // null unless Personalize holdback

    console.log({
        visitorIdentity,
        campaignType,
        campaignIdentity,
        campaignName,
        variationIdentity,
        variationName,
        targetIdentity,
        targetName
    });
}]);

Use cases

  • Analytics Integration: Automatically push variation data to Google Tag Manager or other analytics platforms to track which variations visitors are exposed to and it affects their behavior.
  • CRM Integration: Sync variation data with CRM systems to tailor follow-up communications based on the variations visitors have seen, enhancing the personalization of marketing efforts.
  • Feature Flag Management: Use the variation data to toggle features on or off in your application based on the variation a visitor is bucketed into.

Notes

  • If the listener is registered after the variation applied event is fired, previously queued events are replayed to the callback.
  • When consent gating is enabled on the account, the callback may be deferred until consent is granted.