Skip to content

Commit

Permalink
Feature: implement google analytics 4 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk authored Aug 12, 2022
1 parent 8f42c00 commit 8442ba0
Show file tree
Hide file tree
Showing 22 changed files with 1,824 additions and 527 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules

vendor

assets/dist

languages/*
Expand Down
79 changes: 54 additions & 25 deletions assets/src/js/give-ga-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,69 @@
*/

jQuery.noConflict();
(function( $ ) {
(function ($) {

/**
* Toggle Conditional Form Fields
*
* @since: 1.0
*/
var toggle_ga_fields = function() {
/**
* Toggle Conditional Form Fields
*
* @since: 1.0
*/
const toggle_ga_fields = function () {

var ga_tracking_customize = $( 'input[name="google_analytics_tracking_vals"]' );
var ga_tracking_customize = $('input[name="google_analytics_tracking_vals"]');

ga_tracking_customize.on( 'change', function() {
ga_tracking_customize.on('change', function () {

var ga_tracking_customize_val = $( this ).filter( ':checked' ).val();
var ga_tracking_customize_val = $(this).filter(':checked').val();

if ( 'undefined' === typeof ga_tracking_customize_val ) {
return;
}
if ('undefined' === typeof ga_tracking_customize_val) {
return;
}

if ( ga_tracking_customize_val === 'default' ) {
$( '.give-ga-advanced-field' ).hide();
} else {
$( '.give-ga-advanced-field' ).show();
}
if (ga_tracking_customize_val === 'default') {
$('.give-ga-advanced-field').hide();
} else {
$('.give-ga-advanced-field').show();
}

} ).change();
}).change();

};
};

// On DOM Ready
$( function() {
/**
* Toggle Conditional Google Analytics 4 Form Fields
*
* @unreleased
*/
const toggle_google_analytics_4_fields = function () {

toggle_ga_fields();
const ga_tracking_mode = $('input[name="google_tracking_mode"]');

} );
ga_tracking_mode.on('change', function () {

})( jQuery );
const ga_tracking_mode_val = $(this).filter(':checked').val();

if ('undefined' === typeof ga_tracking_mode_val) {
return;
}

if (ga_tracking_mode_val === 'universal-analytics') {
$('.give-universal-analytics').removeClass('give-hidden');
$('.give-google-analytics-4').addClass('give-hidden');
} else {
$('.give-universal-analytics').addClass('give-hidden');
$('.give-google-analytics-4').removeClass('give-hidden');
}

}).change();

};

// On DOM Ready
$(function () {

toggle_ga_fields();
toggle_google_analytics_4_fields();
});

})(jQuery);
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "impress-org/give-google-analytics",
"type": "wordpress-plugin",
"homepage": "https://givewp.com/",
"description": "Give - Google Analytics Donation Tracking: Add Google Analytics Enhanced eCommerce tracking functionality to Give to track donations.",
"support": {
"issues": "https://github.com/impress-org/give-google-analytics/issues"
},
"autoload": {
"psr-4": {
"GiveGoogleAnalytics\\": "src/"
}
},
"config": {
"platform": {
"php": "7.0"
}
}
}
21 changes: 21 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion give-google-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Text Domain: give-google-analytics
*/

use GiveGoogleAnalytics\Donations\ServiceProvider;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -22,7 +24,7 @@

// Min. Give version.
if ( ! defined( 'GIVE_GOOGLE_ANALYTICS_MIN_GIVE_VERSION' ) ) {
define( 'GIVE_GOOGLE_ANALYTICS_MIN_GIVE_VERSION', '2.6.0' );
define( 'GIVE_GOOGLE_ANALYTICS_MIN_GIVE_VERSION', '2.21.3' );
}

// Plugin File.
Expand Down Expand Up @@ -328,3 +330,25 @@ function Give_Google_Analytics() {

Give_Google_Analytics();
}

// Autoloader
require __DIR__ . '/vendor/autoload.php';

/**
* Load the Service Providers with Give core. This *must* remain outside of the Give_Google_Analytics class
* as it is a completely different bootstrapping system and cannot run inside of the plugins_loaded hook.
*
* @unreleased
*/
add_action('before_give_init', function () {
// Check Give min required version.
if (Give_Google_Analytics()->get_environment_warning()) {
$service_providers = [
ServiceProvider::class
];

foreach ($service_providers as $service_provider) {
give()->registerServiceProvider($service_provider);
}
}
});
Loading

0 comments on commit 8442ba0

Please sign in to comment.