function acquia_lift_personalize_option_set_insert in Acquia Lift Connector 7.2
Implements hook_personalize_option_set_insert().
File
- ./
acquia_lift.module, line 1007 - acquia_lift.module Provides Acquia Lift-specific personalization functionality.
Code
function acquia_lift_personalize_option_set_insert($option_set) {
$agent = personalize_agent_load($option_set->agent);
if (!acquia_lift_is_targeting_agent($agent)) {
return;
}
// Create a goal for hte option set. If it's a fields-based option set we first
// check whether this is the configured behavior.
if ($option_set->plugin == 'fields') {
$field = field_info_field($option_set->data['personalize_fields_field_name']);
if (!isset($field['settings']['personalize']) || !$field['settings']['personalize']['enabled'] || !isset($field['settings']['personalize']['create_goal']) || !$field['settings']['personalize']['create_goal']) {
return;
}
}
elseif (!variable_get('acquia_lift_auto_goal', TRUE)) {
return;
}
// Create a goal for every inserted option set.
$js_id = personalize_stringify_osid($option_set->osid);
$selector = isset($option_set->data['personalize_elements_selector']) ? $option_set->data['personalize_elements_selector'] : '[data-personalize=' . $js_id . ']';
$plugin = 'link';
$action_label = t('Clicks') . ' ' . personalize_sanitize_string($option_set->label);
$action_name = personalize_generate_machine_name($action_label, 'visitor_actions_machine_name_exists', '_');
$pages = empty($field['settings']['personalize']['goal_pages']) ? '' : $field['settings']['personalize']['goal_pages'];
$action = array(
'label' => $action_label,
'machine_name' => $action_name,
'plugin' => $plugin,
'client_side' => 1,
'identifier' => $selector,
'event' => 'click',
'pages' => $pages,
'data' => array(
'auto_created' => $option_set->osid,
),
'limited_use' => 1,
);
// Allow the plugin to modify the action before saving.
if ($class = ctools_plugin_load_class('visitor_actions', 'actionable_element', $plugin, 'handler')) {
$action = call_user_func_array(array(
$class,
'actionPresave',
), array(
$action,
));
}
if (visitor_actions_save_action($action)) {
personalize_goal_save($option_set->agent, $action_name, 1);
}
}