Skip to content

Commit

Permalink
Merge pull request #1087 from laterpay/fix/category-data-ga
Browse files Browse the repository at this point in the history
Fix issue with missing categories in block editor
  • Loading branch information
thrijith authored Jan 11, 2019
2 parents 4805ec1 + 569080f commit f36ac5d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions laterpay/asset_sources/js/laterpay-post-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,26 @@
var eventCategory = 'LP WP Post';
var commonLabel = lpVars.gaData.sandbox_merchant_id + ' | ' + lpVars.postId + ' | ';

var selectedCategories = $('#categorychecklist :checkbox:checked');
var categoryLabel = [];

// Loop through selected categories and store in an array.
$.each( selectedCategories, function( i ) {
categoryLabel.push($('#'+selectedCategories[i].id).parent().text().trim());
} );
// Check editor type to get selected categories in post.
if ( ! wp.data ) {
var selectedCategories = $('#categorychecklist :checkbox:checked');

// Loop through selected categories and store in an array.
$.each( selectedCategories, function( i ) {
categoryLabel.push($('#'+selectedCategories[i].id).parent().text().trim());
} );
} else {
var selectedCategoriesGB =
$('div.editor-post-taxonomies__hierarchical-terms-list :checkbox:checked');

// Loop through checked categories and store label text in an array.
$.each( selectedCategoriesGB, function( i ) {
categoryLabel.push($(selectedCategoriesGB[i]).next( 'label' ).text().trim());
} );

}

// Send GA event with category details.
lpGlobal.sendLPGAEvent( 'Post Published', eventCategory, commonLabel + categoryLabel.join(',') );
Expand Down

0 comments on commit f36ac5d

Please sign in to comment.