Plugin Directory

Changeset 3145946


Ignore:
Timestamp:
09/03/2024 12:37:19 PM (18 months ago)
Author:
codenlassen
Message:

feat: add cookie consent option

Location:
simplest-analytics/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • simplest-analytics/trunk/README.txt

    r2982206 r3145946  
    44Tags: analytics, statistic, tracking, cookieless, video tracking
    55Requires at least: 4.0
    6 Tested up to: 6.3.2
     6Tested up to: 6.6.1
    77Requires PHP: 7.4
    8 Stable tag: 1.3.1
     8Stable tag: 1.3.2
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8383== Changelog ==
    8484
     85= 1.3.2 - 2024-09-03 =
     86* added possibility to define relevant cookie that needs to be set bevor tracking
     87
    8588= 1.3.1 - 2023-10-22 =
    8689* removed max events and max parameters from 5 to unlimited
  • simplest-analytics/trunk/admin/structure.php

    r2982206 r3145946  
    55
    66
     7$option_name_general = 'simplest_analytivs_general';
    78$option_name_paras = 'simplest_analytivs_url_para';
    89$option_name_events = 'simplest_analytivs_events';
    9 $tab = "url_paras";
     10$tab = "general";
    1011
    1112// Processing form data when form is submitted
    12 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit_urlparas"])) {
     13if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit_general"])) {
     14    $general_options = [];
     15    $general_options["cookie_name"] = isset($_POST["cookie_name"]) ? sanitize_text_field(trim($_POST["cookie_name"])) : "";
     16    $general_options["cookie_value"] = isset($_POST["cookie_value"]) ? sanitize_text_field(trim($_POST["cookie_value"])) : "";
     17
     18    if ($general_options["cookie_name"] == "" || $general_options["cookie_value"] == "") {
     19        $general_options["cookie_name"] = "";
     20        $general_options["cookie_value"] = "";
     21    }
     22
     23    update_option($option_name_general, $general_options);
     24} else if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit_urlparas"])) {
    1325
    1426    $get_parameters = isset($_POST["parameter"]) ? array_map('sanitize_title', $_POST["parameter"]) : array();
     
    88100}
    89101
     102$general_options = get_option($option_name_general);
    90103
    91104
     
    98111
    99112    <nav class="nav-tab-wrapper woo-nav-tab-wrapper" style="margin-bottom:10px;">
     113        <a id="general" onclick="simplest_analytics_toggle_tabs_by_id(this)"
     114            class="nav-tab  <?php echo $tab == "general" ? 'nav-tab-active' : '' ?>">
     115            <?php echo esc_html__('General', 'simplest-analytics') ?>
     116        </a>
    100117        <a id="urlparas" onclick="simplest_analytics_toggle_tabs_by_id(this)"
    101118            class="nav-tab  <?php echo $tab == "url_paras" ? 'nav-tab-active' : '' ?>">
     
    115132        </a>
    116133    </nav>
     134
     135    <!-- tab: general -->
     136    <div id="tab_general" class="all_tabs" <?php echo $tab == "general" ? '' : ' style="display:none"' ?>>
     137        <form method="post" action="" class="simplest_analytics_form">
     138            <table class="settings_table">
     139                <tr class="head_th">
     140                    <th></th>
     141                    <th>
     142                        <?php echo __('Cookie Name', 'simplest-analytics') ?>
     143                    </th>
     144                    <th>
     145                        <?php echo __('Cookie Value', 'simplest-analytics') ?>
     146                    </th>
     147                </tr>
     148
     149                <tr>
     150                    <th></th>
     151                    <td colspan="2">
     152                        <?php echo __('If you want to require a certain cookie to be set before data is tracked please fill out the fields. Otherwise leave the fields empty', 'simplest-analytics') ?>
     153                    </td>
     154                </tr>
     155
     156
     157
     158                <tr>
     159                    <th>
     160                        <?php echo __('Cookie', 'simplest-analytics') ?>
     161                    </th>
     162                    <td>
     163                        <input type="text" name="cookie_name"
     164                            value="<?php echo isset($general_options["cookie_name"]) ? esc_html($general_options["cookie_name"]) : "" ?>" />
     165                        <span class="desc">
     166                            <?php echo __('Name of the cookie that has to be set to allow tracking. E.g. analytics_consent', 'simplest-analytics') ?>
     167                        </span>
     168
     169                    </td>
     170                    <td>
     171                        <input type="text" name="cookie_value"
     172                            value="<?php echo isset($general_options["cookie_value"]) ? esc_html($general_options["cookie_value"]) : "" ?>" />
     173                        <span class="desc">
     174                            <?php echo __('Value that has to be set. E.g. true or yes or others', 'simplest-analytics') ?>
     175                        </span>
     176
     177                    </td>
     178                </tr>
     179
     180
     181            </table>
     182            <input type="submit" name="submit_general" style="margin-top:20px;" class="button-primary"
     183                value="<?php echo __('save general settings', 'simplest-analytics') ?>" />
     184        </form>
     185    </div>
     186    <!-- END tab: general -->
    117187
    118188    <!-- tab: url parameters -->
     
    485555                        if ($.inArray(this_val, para) !== -1) {
    486556                            var alert_txt = '<?php echo esc_html__('Please use unique names. This name is used multiple times:', 'simplest-analytics') ?>';
    487                             alert(alert_txt+' '+this_val);
     557                            alert(alert_txt + ' ' + this_val);
    488558                            e.preventDefault();
    489559                            return false;
  • simplest-analytics/trunk/includes/class-activator.php

    r2982206 r3145946  
    88 *
    99 */
    10 class Simplest_Analytics_Activator {
     10class Simplest_Analytics_Activator
     11{
    1112
    1213    /**
    1314     * set up options necessary for functionality of this plugin to wp_options
    1415     */
    15     public static function activate() {
     16    public static function activate()
     17    {
    1618
    1719        // create webanalytics table
    1820        global $wpdb;
    1921        $charset_collate = $wpdb->get_charset_collate();
    20        
     22
    2123        $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}simplest_analytics` (
    2224            id bigint(50) NOT NULL AUTO_INCREMENT,
     
    3335            PRIMARY KEY  (id)
    3436        ) $charset_collate;";
    35        
     37
    3638        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    3739        dbDelta($sql);
     
    4244         * Set Up Plugin Version
    4345         */
    44          
    45          update_option( 'simplest_analytics_version', '1.3.1' );
    4646
    47          /**
     47        update_option('simplest_analytics_version', '1.3.2');
     48
     49        /**
    4850         * Set Up tracking url parameter
    4951         */
     
    5153        // check if simplest_analytivs_url_para is already set
    5254        $para_options = get_option('simplest_analytivs_url_para');
    53         if ( !isset($para_options) ) {
     55        if (!isset($para_options)) {
    5456            $example_para["campaign"] = "Campaign Name";
    55             update_option( 'simplest_analytivs_url_para', $example_para );
     57            update_option('simplest_analytivs_url_para', $example_para);
    5658        }
    5759
    58        
     60
    5961    }
    6062
  • simplest-analytics/trunk/includes/class-simplest-analytics.php

    r2982206 r3145946  
    2929            $this->version = SIMPLEST_ANALYTICS_VERSION;
    3030        } else {
    31             $this->version = '1.3.1';
     31            $this->version = '1.3.2';
    3232        }
    3333        $this->simplest_analytics = 'simplest-analytics';
  • simplest-analytics/trunk/includes/class-uninstall.php

    r2847231 r3145946  
    88 *
    99 */
    10 class Simplest_Analytics_Uninstaller {
     10class Simplest_Analytics_Uninstaller
     11{
    1112
    1213    /**
     
    1415     *
    1516     */
    16     public static function uninstall() {
     17    public static function uninstall()
     18    {
    1719
    18         global $wpdb;
    19         $table_name = $wpdb->prefix . 'simplest_analytics';
    20         $sql = "DROP TABLE IF EXISTS $table_name";
    21         $wpdb->query($sql);
    22        
     20        global $wpdb;
     21        $table_name = $wpdb->prefix . 'simplest_analytics';
     22        $sql = "DROP TABLE IF EXISTS $table_name";
     23        $wpdb->query($sql);
     24
    2325        // delete all plugin created options
    24         delete_option('simplest_analytics_version');
     26        delete_option('simplest_analytics_version');
    2527        delete_option('simplest_analytivs_url_para');
    2628        delete_option('simplest_analytivs_events');
    27        
     29        delete_option('simplest_analytivs_general');
    2830
    2931    }
  • simplest-analytics/trunk/public/class-public.php

    r2979293 r3145946  
    7474
    7575                function onTrackedVideoFrame<?php echo esc_html($randmom_id) ?>(currentTime, duration, video_wrapper_id) {
     76                    var allowed = simplest_analytics_is_allowed();
     77                    if (!allowed) {
     78                        return;
     79                    }
    7680                    var percentage = Math.floor((currentTime / duration) * 100);
    7781                    var one_sec = $("#" + video_wrapper_id + " .simplest_analytics_video_sec_1").val();
     
    186190    {
    187191
     192        $general_options = get_option('simplest_analytivs_general');
     193        $cookie_name = isset($general_options['cookie_name']) ? sanitize_text_field($general_options['cookie_name']) : '';
     194        $cookie_value = isset($general_options['cookie_value']) ? sanitize_text_field($general_options['cookie_value']) : '';
     195
     196
    188197
    189198        ?>
    190199        <script>
     200
     201            function simplest_analytics_is_allowed() {
     202
     203                try {
     204
     205                    var required_cookie_name = "<?php echo esc_html($cookie_name) ?>";
     206                    var required_cookie_value = "<?php echo esc_html($cookie_value) ?>";
     207                    if (required_cookie_name === "" && required_cookie_value === "") {
     208                        return true;
     209                    }
     210
     211                    var name = required_cookie_name + "=";
     212                    var decodedCookie = decodeURIComponent(document.cookie);
     213                    var ca = decodedCookie.split(';');
     214                    for (var i = 0; i < ca.length; i++) {
     215                        var c = ca[i];
     216                        while (c.charAt(0) === ' ') {
     217                            c = c.substring(1);
     218                        }
     219                        if (c.indexOf(name) === 0) {
     220                            if (c.substring(name.length, c.length) === required_cookie_value) {
     221                                return true;
     222                            }
     223                        }
     224                    }
     225                    return false;
     226                } catch (e) {
     227                    return false;
     228                }
     229
     230            }
     231
    191232            function simplest_analytics_track(type, event) {
     233                var allowed = simplest_analytics_is_allowed();
     234                if (!allowed) {
     235                    return;
     236                }
    192237                if (event !== "") {
    193238                    var event = "&event=" + event;
     
    256301        ?>
    257302        <script>
    258             var wc_simplest_analytics_url = "<?php echo esc_url(admin_url('admin-ajax.php')) ?>?action=simplest_analytics_tracking_action&type=event&event=sale&ref=" + document.referrer;
    259             var xhttp = new XMLHttpRequest();
    260             xhttp.onreadystatechange = function () {
    261                 if (this.readyState == 4 && this.status == 200) {
    262                     // Typical action to be performed when the document is ready:
    263                     //alert(xhttp.responseText);
    264                 }
    265 
    266             };
    267             xhttp.open("GET", wc_simplest_analytics_url, true);
    268             xhttp.send();
     303            var allowed = simplest_analytics_is_allowed();
     304            if (allowed) {
     305
     306                var wc_simplest_analytics_url = "<?php echo esc_url(admin_url('admin-ajax.php')) ?>?action=simplest_analytics_tracking_action&type=event&event=sale&ref=" + document.referrer;
     307                var xhttp = new XMLHttpRequest();
     308                xhttp.onreadystatechange = function () {
     309                    if (this.readyState == 4 && this.status == 200) {
     310                        // Typical action to be performed when the document is ready:
     311                        //alert(xhttp.responseText);
     312                    }
     313
     314                };
     315                xhttp.open("GET", wc_simplest_analytics_url, true);
     316                xhttp.send();
     317            }
    269318        </script>
    270319        <?php
  • simplest-analytics/trunk/simplest-analytics.php

    r2982206 r3145946  
    1313 * Plugin URI:        https://www.coden-lassen.de
    1414 * Description:       Serverside and cookieless webanalytics.
    15  * Version:           1.3.1
     15 * Version:           1.3.2
    1616 * Author:            Stefan Klaes
    1717 * Author URI:        https://www.coden-lassen.de/wordpress-freelancer
     
    3232/**
    3333 * Currently plugin version:
    34  * version 1.3.1
     34 * version 1.3.2
    3535 */
    3636 
    37 define( 'SIMPLEST_ANALYTICS_VERSION', '1.3.1' );
     37define( 'SIMPLEST_ANALYTICS_VERSION', '1.3.2' );
    3838
    3939
Note: See TracChangeset for help on using the changeset viewer.