Plugin Directory

Changeset 2903367


Ignore:
Timestamp:
04/24/2023 02:50:30 PM (3 years ago)
Author:
wiredimpact
Message:
  • Upgraded Google Analytics tracking to work with Google Analytics 4.
Location:
wired-impact-volunteer-management/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wired-impact-volunteer-management/trunk/README.txt

    r2826554 r2903367  
    55Tested up to: 6.1
    66Requires PHP: 5.2.4
    7 Stable tag: 1.4.9
     7Stable tag: 1.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    110110== Changelog ==
    111111
     112= 1.5 =
     113* Upgraded Google Analytics tracking to work with Google Analytics 4.
     114
    112115= 1.4.9 =
    113116* Tested up to WordPress 6.1.
  • wired-impact-volunteer-management/trunk/frontend/js/wi-volunteer-management-public.js

    r1578967 r2903367  
    1 (function( $ ) {
     1( function( $ ) {
     2
    23    'use strict';
    34
    4     //Document ready
    5     $(function() {
     5    // Document ready.
     6    $( function() {
    67
    78        /**
    8          * Handle submission of volunteer opportunity sign up form inclding validation and AJAX processing.
     9         * Handle submission of volunteer opportunity sign up form including
     10         * validation and AJAX processing.
    911         */
    10         $( '#wivm-sign-up-form input[type=submit]' ).click(function(e){
     12        $( '#wivm-sign-up-form input[type=submit]' ).click( function( e ) {
     13
    1114            e.preventDefault();
    1215            var $this = $( this ),
     
    1619
    1720            form_valid = validate_sign_up_form();
    18             if( form_valid === true ){
     21            if ( form_valid === true ) {
     22
    1923                submit_sign_up_form( $this );
    20             }
    21             else { //Allow submission again if there were errors
     24
     25            } else { // Allow submission again if there were errors.
     26
    2227                $this.prop( "disabled", false );
    2328            }
    24         });
     29        } );
    2530
    2631    });
     
    2833    /**
    2934     * Validate the volunteer opportunity sign up form.
     35     *
    3036     * @return {bool} Whether the form is valid.
    3137     */
    3238    function validate_sign_up_form(){
     39
    3340        var has_errors = false;
    3441
    35         //Show an error and don't submit if the honeypot exists and is filled in
     42        // Show an error and don't submit if the honeypot exists and is filled in.
    3643        var hp = $( '#wivm_hp' );
    37         if( hp.length && hp.val() !== '' ){
     44        if ( hp.length && hp.val() !== '' ) {
     45
    3846            has_errors = true;
    3947        }
    4048
    41         //Make sure each field is filled in and that email addresses are valid
    42         $( '#wivm-sign-up-form input[type=text]:not(#wivm_hp), #wivm-sign-up-form input[type=email]' ).each(function() {
    43             if( this.value === '' ) {
    44                 $( this ).addClass( 'field-error' );
    45                 has_errors = true;
    46             }
    47             else if ( this.type === 'email' && !validate_email( this.value ) ){
    48                 $( this ).addClass( 'field-error' );
    49                 has_errors = true;
    50             }
    51             else {
    52                 $( this ).removeClass( 'field-error' );
    53             }
    54         });
     49        // Make sure each field is filled in and that email addresses are valid.
     50        $( '#wivm-sign-up-form input[type=text]:not(#wivm_hp), #wivm-sign-up-form input[type=email]' ).each( function() {
    5551
    56         //If not valid return false.
    57         if( has_errors === true ){
    58             $( '.volunteer-opp-message.loading, .volunteer-opp-message.success' ).slideUp();
    59             $( '.volunteer-opp-message.error' ).slideDown();
    60             return false;
    61         }
    62         else {
    63             $( '.volunteer-opp-message' ).slideUp();
    64             return true;
    65         }
     52            if ( this.value === '' ) {
     53
     54                $( this ).addClass( 'field-error' );
     55                has_errors = true;
     56
     57            } else if ( this.type === 'email' && ! validate_email( this.value ) ) {
     58
     59                $( this ).addClass( 'field-error' );
     60                has_errors = true;
     61
     62            } else {
     63
     64                $( this ).removeClass( 'field-error' );
     65            }
     66        } );
     67
     68        // If not valid return false.
     69        if ( has_errors === true ) {
     70
     71            $( '.volunteer-opp-message.loading, .volunteer-opp-message.success' ).slideUp();
     72            $( '.volunteer-opp-message.error' ).slideDown();
     73
     74            return false;
     75
     76        } else {
     77
     78            $( '.volunteer-opp-message' ).slideUp();
     79
     80            return true;
     81        }
    6682    }
    6783
     
    7389     */
    7490    function validate_email( email ){
     91
    7592        var email_regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
    7693
    77         if( email_regex.test( email ) ){
    78             return true;
    79         }
    80         else {
    81             return false;
    82         }
     94        if ( email_regex.test( email ) ) {
     95
     96            return true;
     97
     98        } else {
     99
     100            return false;
     101        }
    83102    }
    84103
     
    87106     */
    88107    function submit_sign_up_form( submit_button ){
    89         //Show messages to user
     108
     109        // Show messages to user.
    90110        $( '.volunteer-opp-message.error' ).slideUp();
    91111        $( '.volunteer-opp-message.loading' ).slideDown();
     
    100120                $( '.volunteer-opp-message.loading' ).slideUp();
    101121               
    102                 //If submitter was RSVPed successfully
    103                 if( response === 'rsvped' ){
     122                if ( response === 'rsvped' ) { // If submitter was RSVPed successfully.
     123
    104124                    $( '.volunteer-opp-message.success' ).slideDown();
    105125                    submit_button.prop( "disabled", false );
    106                     track_google_analytics( 'RSVP Success' );
    107                 }
    108                 //If submitter had already RSVPed
    109                 else if( response === 'already_rsvped'){
     126                    track_google_analytics( 'Success' );
     127
     128                } else if ( response === 'already_rsvped') { // If submitter had already RSVPed.
     129
    110130                    $( '.volunteer-opp-message.already-rsvped' ).slideDown();
    111131                    submit_button.prop( "disabled", false );
    112                     track_google_analytics( 'RSVP Failure: Already RSVPed' );
    113                 }
    114                 //If submitter tried to sign up, but there are no spots left.
    115                 else if( response === 'rsvp_closed' ){
     132                    track_google_analytics( 'Failure: Already Signed Up' );
     133
     134                } else if ( response === 'rsvp_closed' ) { // If submitter tried to sign up, but there are no spots left.
     135
    116136                    $( '.volunteer-opp-message.rsvp-closed' ).slideDown();
    117137                    $( '#wivm-sign-up-form' ).slideUp();
    118                     track_google_analytics( 'RSVP Failure: No More Open Spots' );
     138                    track_google_analytics( 'Failure: No More Open Spots' );
    119139                }
    120140            }
     
    123143
    124144    /**
    125      * Track volunteer opportunity action as an event within Google Analytics.
     145     * Track an event within Google Analytics when volunteers sign up.
    126146     *
    127      * This only works in Universal Analytics, and does not in Classic Analytics.
    128      *
    129      * @param {string} action The action that was completed (i.e. "Successful RSVP")
     147     * @param {string} sign_up_result The result of the sign up attempt.
    130148     */
    131     function track_google_analytics( action ){
    132         //Determine global analytics object name
    133         var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
    134         if( typeof ga == 'function' ){
    135             //Track as an event
    136             ga( 'send', {
    137                 hitType:        'event',
    138                 eventCategory:  'Volunteer Opportunity',
    139                 eventAction:    action
    140             });
     149    function track_google_analytics( sign_up_result ){
     150       
     151        if ( typeof gtag === 'function' ) {
     152
     153            gtag( 'event', 'volunteer_opportunity_submit', {
     154                'sign_up_result': sign_up_result,
     155            } );
    141156        }
    142157    }
    143158
    144 
    145159})( jQuery );
  • wired-impact-volunteer-management/trunk/includes/class-wi-volunteer-management.php

    r2826554 r2903367  
    6969
    7070        $this->plugin_name = 'wired-impact-volunteer-management';
    71         $this->version     = '1.4.9';
     71        $this->version     = '1.5';
    7272
    7373        $this->load_dependencies();
  • wired-impact-volunteer-management/trunk/wivm.php

    r2826554 r2903367  
    1717 * Plugin URI:        https://wiredimpact.com/wordpress-plugins-for-nonprofits/volunteer-management/
    1818 * Description:       A simple, free way to keep track of your nonprofit’s volunteers and opportunities.
    19  * Version:           1.4.9
     19 * Version:           1.5
    2020 * Author:            Wired Impact
    2121 * Author URI:        https://wiredimpact.com
Note: See TracChangeset for help on using the changeset viewer.