AB Paragraphs - Changelog
Performance Optimization for Suggestions
Problem
Tracking code suggestions were regenerating on every content change, causing noticeable lag during editing.
Optimizations Implemented
- Content Caching with Hash Comparison
- Added
simpleHash()function to compute content fingerprints - Skips regeneration when content hash matches cached value
- Separate cache for variant A and B
- Added
- Debounce Delay Increased β Changed from 300ms to 500ms to reduce rapid recalculations
- Delayed Loader Display β Loader only shows after 150ms delay (prevents flash for fast operations)
- requestAnimationFrame Usage β Prevents blocking the main UI thread during suggestion rendering
- Event Delegation β Single click handler per container instead of per-button (reduces memory usage and improves responsiveness)
- User Feedback β Copy button shows βCopied!β confirmation for 1.5 seconds
Files Modified
js/trackingcode_suggestions.jsβ Performance optimizations
Loading Indicator for Suggestions
Changes
- Added loading throbber when tracking code suggestions are being generated
- Shows "Loading suggestions..." text with animated spinner
- Improves UX by indicating that processing is happening
Files Modified
js/trackingcode_suggestions.jsβ AddedshowLoader()functioncss/trackingcode_suggestions.cssβ Added throbber animation styles
Best Practices Fix
PHP Code Quality Improvements
AbParagraphsSettingsForm.php
- Added dependency injection for
ConfigFactoryInterfaceandModuleHandlerInterface - Added
create()method for proper service container integration - Added return type hints to all methods (
: string,: array,: void,: static) - Added proper
usestatements forUrlclass - Removed unused
$descriptionsvariable
ab_paragraphs.module
- Added proper
usestatements (FieldConfig,Paragraph) - Added return type hints to all functions
- Improved early return pattern in
ab_paragraphs_preprocess_paragraph() - Simplified
ab_paragraphs_form_alter()with early returns - Removed unused
$keyparameter in array_walk_recursive callback
ab_paragraphs.install
- Added file-level docblock
- Added return type hints (
: void) - Translated Dutch comments to English
- Added proper
usestatements - Improved code structure with early returns
JavaScript Improvements
ab_test.js
- Removed all
eval()usage (security improvement) - Replaced hardcoded
console.logwith debug mode flag (drupalSettings.abParagraphsSettings.debug) - Removed all emoji characters from output
- Removed unused
logAbEvent()function - Added
'use strict';directive - Added proper JSDoc documentation for all functions
- Added
drupalSettingsto IIFE parameters - Improved optional chaining compatibility for older browsers
trackingcode_suggestions.js
- Added file-level
@filedocblock - Removed all
console.logstatements - Removed all emoji characters
- Extracted
generateTrackingCode()function for cleaner code - Added
'use strict';directive - Added proper JSDoc documentation
- Used
Drupal.checkPlain()for XSS protection in suggestions output - Added
drupalSettingsto IIFE parameters
YAML/Configuration Improvements
ab_paragraphs.routing.yml
- Translated Dutch
_titleto English ("A/B Paragraphs Settings")
config/schema/ab_paragraphs.schema.yml (NEW)
- Added configuration schema for settings validation
CSS Improvements
trackingcode_suggestions.css
- Added file-level docblock
- Updated class names to match JavaScript
- Improved flexbox layout for suggestions
Files Modified
src/Form/AbParagraphsSettingsForm.phpab_paragraphs.moduleab_paragraphs.installab_paragraphs.routing.ymljs/ab_test.jsjs/trackingcode_suggestions.jscss/trackingcode_suggestions.css
Files Added
config/schema/ab_paragraphs.schema.yml
Caching Fix
Problem
The module was using max-age = 0 and session cache context, which disabled page caching and caused server load.
Root Cause Analysis
- Variant selection happens client-side via JavaScript
- Both variants are always rendered server-side
- JavaScript determines which variant to show/hide
- The server output is deterministic and cacheable
Solution
Removed cache restrictions:
// Before
$variables['#cache']['max-age'] = 0;
$variables['#cache']['contexts'][] = 'session';
// After
// Add cache tag for invalidation on content changes only
$variables['#cache']['tags'][] = 'paragraph:' . $paragraph->id();
Benefits
- Full page caching now works
- Varnish/CDN can cache pages with A/B tests
- Reduced server load
- Cache invalidates correctly when paragraph content changes
Render Refactor - Fix Images and Background Colors
Issues Addressed
- Images not displayed in nested paragraphs
- Background colors not preserved
- Links in running text not getting tracking code
Technical Changes
// Before (problematic)
$html_a = \Drupal::service('renderer')->render($views_a);
$processed_html_a = ab_paragraphs_process_links($html_a, $tracking_code_a);
'#markup' => \Drupal\Core\Render\Markup::create($processed_html_a),
// After (fixed)
$render_a = [];
foreach ($ref_a as $entity) {
$render_a[] = $builder->view($entity, 'default');
}
'content' => $render_a,
'data-tracking-code' => $tracking_code_a,
Benefits
- Lazy loading works correctly
- Responsive images preserved
- Background colors preserved
- All Drupal behaviors work
- Event delegation tracks all links
Added Piwik Pro Support
Changes
- Added Piwik Pro as analytics provider option
- Settings form shows Matomo, Piwik Pro, and Google Analytics
- URL automatically retrieved from module configuration
- Multi-provider tracking support:
_paq(Matomo/Piwik Pro)ppms(Piwik Pro Tag Manager)gtag(Google Analytics)
Files Modified
src/Form/AbParagraphsSettingsForm.phpab_paragraphs.modulejs/ab_test.jsjs/trackingcode_suggestions.js
VCS Label
1.0.0-beta1
Release type
Short description
Numerous fixes and enhancements
Packaged Git sha1
82322744fb567635591ecff5a49d09b2a9dd1e66
Release files