Plugin Directory

Changeset 2658193


Ignore:
Timestamp:
01/15/2022 08:54:39 PM (4 years ago)
Author:
strategicplugins
Message:

Version 1.1 - Added custom hooks so developers can add their own custom targeting rules and actions.

Location:
targeted-actions
Files:
12 edited
10 copied

Legend:

Unmodified
Added
Removed
  • targeted-actions/tags/1.1/TargetedUserActions.php

    r2649595 r2658193  
    55Plugin Name: Targeted User Actions
    66description: A plugin that allows you to target users of your website and perform custom actions, including showing a pop-up or setting a cookie, only for matching users.
    7 Version: 1.0
     7Version: 1.1
    88Author: StrategicPlugins.com
    99Author URI: https://strategicplugins.com
  • targeted-actions/tags/1.1/assets/js/admin.js

    r2649595 r2658193  
    2929    // CodeMirror
    3030   
    31     if($('#modal-html-codemirror').length > 0) {
    32         wp.codeEditor.initialize($('#modal-html-codemirror'), cm_settings);
     31    if($('.js-tua-codemirror').length > 0) {
     32        $( ".js-tua-codemirror" ).each(function( index ) {
     33            wp.codeEditor.initialize($(this), cm_settings);
     34        });
    3335    }
    3436
  • targeted-actions/tags/1.1/features/admin/RuleFields.php

    r2649595 r2658193  
    215215    public static function ruleType($value = "") {
    216216
     217    $available_actions = [];
     218    $available_actions["show_modal"] = 'Show a Modal / Popup Window';
     219    $available_actions["set_cookie"] = 'Set a cookie on the user\'s browser';
     220
     221    // Use the tua_define_actions hook to add a new option
     222    $available_actions = apply_filters( 'tua_define_actions', $available_actions);
     223
    217224        $html = '
    218225            <div class="form-row settings-row">
     
    221228                <div class="form-rule-select">
    222229                    ' . Form::radio("rule_action",
    223                       [
    224                         'show_modal' => 'Show a Modal / Popup Window',
    225                         'set_cookie' => 'Set a cookie on the user\'s browser'
    226                       ],
     230                      $available_actions,
    227231                      [
    228232                      'label' => 'Select Rule Action',
  • targeted-actions/tags/1.1/features/admin/TUAAdmin.php

    r2649595 r2658193  
    252252    $rule_to_edit = "";
    253253    $update_rule = "";
     254    $rule_data = "";
    254255
    255256    if(Form::getArg("ruleID") != "" AND is_numeric(Form::getArg("ruleID"))) {
     
    331332                (isset($rule_data["required_visit_count"]) ? $rule_data["required_visit_count"] : '')
    332333              ) . '
     334
     335            <!-- TUA Rule Triggers -->
    333336           
    334337          </div>
     
    552555                          'label' => 'Modal HTML',
    553556                          'id' => 'modal-html-codemirror',
     557                          'field_class' => 'js-tua-codemirror',
    554558                          'value' => (isset($rule_data["modal_html"]) ? html_entity_decode($rule_data["modal_html"]) : '')
    555559                        ]) .'
     
    664668              </div>
    665669
     670              <!-- TUA Add Rule Settings -->
     671
    666672            </div>
    667673
     
    678684    ';
    679685
     686    $html = apply_filters( 'tua_update_rule_html', $html, $rule_data);
     687
    680688    echo wp_kses($html, $this->allowedHTML);
    681689
  • targeted-actions/tags/1.1/features/formhandlers/SaveEditRule.php

    r2649595 r2658193  
    204204    $values["cookie_php_only"] = Form::getArg("cookie_php_only");
    205205    $values["cookie_no_overwrite"] = Form::getArg("cookie_no_overwrite");
     206
     207    // Get any custom values for any custom rules created using hooks / outside plugins
     208    $values = apply_filters( 'tua_save_rule_values', $values);
    206209   
     210    // Define values that are required for all rules
    207211    $required_values = ["rule_name", "rule_action"];
     212
     213    // Allow adding values that are required for all rules
     214    // If you're creating a custom plugin using hooks, this usually isn't the place to validate your custom rules
     215    $required_values = apply_filters( 'tua_define_global_required_values', $required_values);
    208216
    209217    if($update === true) {
     
    326334    }
    327335
     336    // If you are creating a custom trigger or action, use this hook to validate any required fields are present
     337    $response = apply_filters( 'tua_validate_and_respond', $response, $values);
     338
    328339    if(isset($response["errors"]) AND count($response["errors"]) > 0) {
    329340      $is_valid = false;
  • targeted-actions/tags/1.1/features/rules/Rules.php

    r2649595 r2658193  
    129129                $rule_trigger_conditions["number_of_website_visits"] = $session_info["visit_count"];
    130130
     131                $rule_trigger_conditions = apply_filters( 'tua_current_conditions', $rule_trigger_conditions);
     132
    131133                // Ensure that only one modal rule triggers per iteration
    132134                $modal_rule_will_fire = false;
     
    257259                        // echo "<p>Evaluating rule: " . $rule["rule_name"] . "</p>";
    258260                       
     261                        // Hook for validating that custom trigger conditions are met
     262                        $conditions_met = apply_filters( 'tua_conditions_met', $conditions_met, $rule, $rule_trigger_conditions);
     263                       
    259264                        $all_conditions_met = true;
    260265
     
    280285                                $this->executeSetCookie($rule);
    281286                            }
     287
     288                            // Custom action for executing custom rules
     289                            do_action("tua_execute_actions", $rule["rule_action"], $rule, $modal_rule_will_fire);
    282290
    283291                        }
  • targeted-actions/tags/1.1/readme.txt

    r2649595 r2658193  
    55Tested up to: 5.8.2
    66Requires PHP: 5.6.40
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: Expat
    99License URI: https://directory.fsf.org/wiki/License:Expat
     
    1414Targeted User Actions is a plugin that allows you to perform actions on your website, such as showing a modal (pop-up) window or setting a cookie, only for users who match criteria that you define.  For instance, with this plugin you can target users who have visited a specific product page on your website more than once across multiple browser sessions, and then show those users a pop-up window that offers them a discount code on the product.
    1515
    16 Easily set up rules to find users who match specific criteria and fire actions only for those users.  You can target users by the current page URL, number of times the user has viewed a page, a user\'s logged in status as well as how many total visits a user has made to your site.  Combine these targeting criteria for even more powerful user targeting.
     16Easily set up rules to find users who match specific criteria and fire actions only for those users.  You can target users by the current page URL, number of times the user has viewed a page, a user's logged in status as well as how many total visits a user has made to your site.  Combine these targeting criteria for even more powerful user targeting.
    1717
    18 If a user matches one of the rules you have defined, you can then perform an action only on that user.  Actions you can perform are launching a modal (pop-up) window or setting a cookie on the user\'s browser.  Our goal is to add more actions in future versions of the plugin, as well as eventually give developers tools to add their own custom targeting metrics and actions via Wordpress hooks.
     18If a user matches one of the rules you have defined, you can then perform an action only on that user.  Actions you can perform are launching a modal (pop-up) window or setting a cookie on the user's browser.  Our goal is to add more actions in future versions of the plugin, as well as eventually give developers tools to add their own custom targeting metrics and actions via Wordpress hooks.
    1919
    2020The plugin can also be configured to not track any users until a specific cookie is present for the user, which makes the plugin compatible with cookie notice plugins that set a cookie only after a user gives consent to be tracked.
    2121
     22== Frequently Asked Questions ==
     23
     24= How does this plugin work? =
     25
     26When a user first visits your website, this plugin creates a unique session ID for that user and stores that session ID in the database.  It also stores a cookie on the user's browser that contains this session ID.  As a user browses your website, each page they load is logged in the database and compared against the targeting rules you define.  If a match is found, your targeting rule fires for that user.  If a user ends their session and comes back, the plugin reads their previous session ID from the saved cookie and associates that previous session ID with that user, allowing users to be tracked across sessions.
     27
     28= What if I cannot track users until they consent? =
     29
     30If you need to obtain consent before tracking users, you can obtain consent using a cookie bar plugin.  You can configure Targeted User Actions to not track users before this consent is obtained, however the plugin also will not be able to execute any actions for a user until consent is obtained.  Determine the name of the cookie your cookie consent plugin saves when a user gives consent, then enter that cookie name in the *Required Cookie Name* box under the Targeted User Actions plugin settings and ensure the *Require that the following cookie be set before tracking users* checkbox is selected.  This will ensure that users are only tracked once they give consent to being tracked.
     31
     32= My rules are not firing, or are firing for every user.  What is wrong? =
     33
     34Ensure that you do not have any caching enabled that may interfere with the Targeted User Actions plugin.  Aggressive caching may serve up the same content for multiple users, which is a problem if you have a rule you want to fire only for specific users.
     35
     36= I am trying to use custom HTML for my modal but some of it is being removed.  Why? =
     37
     38For security reasons, only common HTML tags and attributes are allowed in the code shown in the modal.  We have tried to allow the major common HTML tags and attributes, but if there is one that you require please contact us and we will consider adding it in a future release.
     39
     40== Screenshots ==
     41
     421. Show a modal window only to targeted users.  Use this plugin to give users an additional nudge to complete a purchase by showing a promo code or other content unique to them.
     432. Easily view, edit, disable or delete all of your targeted rules.
     443. Create a new rule and use triggers to determine for which users this rule will fire.
     454. Use the modal builder to easily add content for your modal.  Add text and change the colors of the modal text, button and background.
     465. Are you a developer?  Use custom HTML content inside of your modal to create something unique.
     476. Need to obtain consent before tracking users?  Set a cookie that must be present before the plugin will track your users.
     48
    2249== Changelog ==
     501.1 - Added custom hooks so that developers can create their own targeting rules and actions.
    23511.0 - Initial Plugin Release
  • targeted-actions/trunk/TargetedUserActions.php

    r2649595 r2658193  
    55Plugin Name: Targeted User Actions
    66description: A plugin that allows you to target users of your website and perform custom actions, including showing a pop-up or setting a cookie, only for matching users.
    7 Version: 1.0
     7Version: 1.1
    88Author: StrategicPlugins.com
    99Author URI: https://strategicplugins.com
  • targeted-actions/trunk/assets/js/admin.js

    r2649595 r2658193  
    2929    // CodeMirror
    3030   
    31     if($('#modal-html-codemirror').length > 0) {
    32         wp.codeEditor.initialize($('#modal-html-codemirror'), cm_settings);
     31    if($('.js-tua-codemirror').length > 0) {
     32        $( ".js-tua-codemirror" ).each(function( index ) {
     33            wp.codeEditor.initialize($(this), cm_settings);
     34        });
    3335    }
    3436
  • targeted-actions/trunk/features/admin/RuleFields.php

    r2649595 r2658193  
    215215    public static function ruleType($value = "") {
    216216
     217    $available_actions = [];
     218    $available_actions["show_modal"] = 'Show a Modal / Popup Window';
     219    $available_actions["set_cookie"] = 'Set a cookie on the user\'s browser';
     220
     221    // Use the tua_define_actions hook to add a new option
     222    $available_actions = apply_filters( 'tua_define_actions', $available_actions);
     223
    217224        $html = '
    218225            <div class="form-row settings-row">
     
    221228                <div class="form-rule-select">
    222229                    ' . Form::radio("rule_action",
    223                       [
    224                         'show_modal' => 'Show a Modal / Popup Window',
    225                         'set_cookie' => 'Set a cookie on the user\'s browser'
    226                       ],
     230                      $available_actions,
    227231                      [
    228232                      'label' => 'Select Rule Action',
  • targeted-actions/trunk/features/admin/TUAAdmin.php

    r2649595 r2658193  
    252252    $rule_to_edit = "";
    253253    $update_rule = "";
     254    $rule_data = "";
    254255
    255256    if(Form::getArg("ruleID") != "" AND is_numeric(Form::getArg("ruleID"))) {
     
    331332                (isset($rule_data["required_visit_count"]) ? $rule_data["required_visit_count"] : '')
    332333              ) . '
     334
     335            <!-- TUA Rule Triggers -->
    333336           
    334337          </div>
     
    552555                          'label' => 'Modal HTML',
    553556                          'id' => 'modal-html-codemirror',
     557                          'field_class' => 'js-tua-codemirror',
    554558                          'value' => (isset($rule_data["modal_html"]) ? html_entity_decode($rule_data["modal_html"]) : '')
    555559                        ]) .'
     
    664668              </div>
    665669
     670              <!-- TUA Add Rule Settings -->
     671
    666672            </div>
    667673
     
    678684    ';
    679685
     686    $html = apply_filters( 'tua_update_rule_html', $html, $rule_data);
     687
    680688    echo wp_kses($html, $this->allowedHTML);
    681689
  • targeted-actions/trunk/features/formhandlers/SaveEditRule.php

    r2649595 r2658193  
    204204    $values["cookie_php_only"] = Form::getArg("cookie_php_only");
    205205    $values["cookie_no_overwrite"] = Form::getArg("cookie_no_overwrite");
     206
     207    // Get any custom values for any custom rules created using hooks / outside plugins
     208    $values = apply_filters( 'tua_save_rule_values', $values);
    206209   
     210    // Define values that are required for all rules
    207211    $required_values = ["rule_name", "rule_action"];
     212
     213    // Allow adding values that are required for all rules
     214    // If you're creating a custom plugin using hooks, this usually isn't the place to validate your custom rules
     215    $required_values = apply_filters( 'tua_define_global_required_values', $required_values);
    208216
    209217    if($update === true) {
     
    326334    }
    327335
     336    // If you are creating a custom trigger or action, use this hook to validate any required fields are present
     337    $response = apply_filters( 'tua_validate_and_respond', $response, $values);
     338
    328339    if(isset($response["errors"]) AND count($response["errors"]) > 0) {
    329340      $is_valid = false;
  • targeted-actions/trunk/features/rules/Rules.php

    r2649595 r2658193  
    129129                $rule_trigger_conditions["number_of_website_visits"] = $session_info["visit_count"];
    130130
     131                $rule_trigger_conditions = apply_filters( 'tua_current_conditions', $rule_trigger_conditions);
     132
    131133                // Ensure that only one modal rule triggers per iteration
    132134                $modal_rule_will_fire = false;
     
    257259                        // echo "<p>Evaluating rule: " . $rule["rule_name"] . "</p>";
    258260                       
     261                        // Hook for validating that custom trigger conditions are met
     262                        $conditions_met = apply_filters( 'tua_conditions_met', $conditions_met, $rule, $rule_trigger_conditions);
     263                       
    259264                        $all_conditions_met = true;
    260265
     
    280285                                $this->executeSetCookie($rule);
    281286                            }
     287
     288                            // Custom action for executing custom rules
     289                            do_action("tua_execute_actions", $rule["rule_action"], $rule, $modal_rule_will_fire);
    282290
    283291                        }
  • targeted-actions/trunk/readme.txt

    r2649595 r2658193  
    55Tested up to: 5.8.2
    66Requires PHP: 5.6.40
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: Expat
    99License URI: https://directory.fsf.org/wiki/License:Expat
     
    1212
    1313== Description ==
    14 Targeted User Actions is a plugin that allows you to perform actions on your website, such as showing a modal (pop-up) window or setting a cookie, only for users who match criteria that you define.  For instance, with this plugin you can target users who have visited a specific product page on your website more than once across multiple browser sessions, and then show those users a pop-up window that offers them a discount code on the product.
    1514
    16 Easily set up rules to find users who match specific criteria and fire actions only for those users.  You can target users by the current page URL, number of times the user has viewed a page, a user\'s logged in status as well as how many total visits a user has made to your site.  Combine these targeting criteria for even more powerful user targeting.
    17 
    18 If a user matches one of the rules you have defined, you can then perform an action only on that user.  Actions you can perform are launching a modal (pop-up) window or setting a cookie on the user\'s browser.  Our goal is to add more actions in future versions of the plugin, as well as eventually give developers tools to add their own custom targeting metrics and actions via Wordpress hooks.
    19 
    20 The plugin can also be configured to not track any users until a specific cookie is present for the user, which makes the plugin compatible with cookie notice plugins that set a cookie only after a user gives consent to be tracked.
    21 
    22 == Changelog ==
    23 1.0 - Initial Plugin Release
     15This readme file is used by the Wordpress repo to pull the proper version using the stable tag.  View the plugin description and changelog in the newest plugin version's readme file.
Note: See TracChangeset for help on using the changeset viewer.