Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to show notifications for new features in matomo for wordpress #1226

Merged
merged 27 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a354b8b
add new feature to display hard coded notifications for new features …
diosmosis Dec 4, 2024
3545fc9
add JS to dismiss whats new notification + start on notification dot css
diosmosis Dec 4, 2024
1f0280b
add filter to allow other parts of MWP to edit matomo submenu informa…
diosmosis Dec 4, 2024
0c2241b
revert menu changes and go to javascript approach so pages added outs…
diosmosis Dec 4, 2024
c152857
in wordpress:download-test-screenshots use curl CLI command instead o…
diosmosis Dec 6, 2024
bf502ef
try to fix e2e test failure
diosmosis Dec 6, 2024
cce78b7
Merge branch 'develop' into crashanalytics-new
diosmosis Dec 9, 2024
f193c51
finalize look of promo and marketplace changes
diosmosis Dec 12, 2024
407fccc
allow whats new notifications to determine exactly when they should s…
diosmosis Dec 12, 2024
627b610
translate crash analytics promo text
diosmosis Dec 12, 2024
c181700
stub unit tests for new WhatsNewNotifications feature
diosmosis Dec 12, 2024
4da419a
add first unit test for WhatsNewNotifications
diosmosis Dec 12, 2024
ffd3434
add tests for WhatsNewNotification::is_active
diosmosis Dec 12, 2024
91809cf
add tests for register_hooks
diosmosis Dec 12, 2024
85a82f1
add tests for on_admin_notices hook
diosmosis Dec 12, 2024
c09c05d
finish unit tests for WhatsNewNotifications feature and get to pass
diosmosis Dec 14, 2024
704dde1
add e2e test for notifications
diosmosis Dec 15, 2024
a20fb5f
fix import
diosmosis Dec 16, 2024
e00f799
debug failing test
diosmosis Dec 16, 2024
c0bc5f4
fix random new url path issue in test
diosmosis Dec 16, 2024
1a1c75e
update existing screenshots and add pause
diosmosis Dec 16, 2024
3dd391a
Merge branch 'develop' into crashanalytics-new
diosmosis Dec 18, 2024
13b2645
update expected screenshot
diosmosis Dec 18, 2024
b2de1d9
fill out PR TODO
diosmosis Dec 18, 2024
a702fd5
do not show promo notifications on get started page so users has a cl…
diosmosis Dec 18, 2024
5d5d764
update expected screenshot
diosmosis Dec 19, 2024
6136a5d
do not report "could not set" errors when scheduling cron events
diosmosis Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions assets/css/admin-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,52 @@ table.matomo-tracking-form th {
-ms-transform: translateX(1.03em);
transform: translateX(1.03em);
}

#toplevel_page_matomo a {
position: relative;
display: inline-block;
}

#toplevel_page_matomo .matomo-notification-dot::before {
content: " ";
position: absolute;
display: inline-block;
width: 6px;
height: 6px;
background-color: red;
border-radius: 50%;
right: 4px;
}

.notice.matomo-whats-new {
border-left-color: #9D2235;
}

.notice.matomo-whats-new .button-primary {
background-color: #9D2235;
border-color: #9D2235;
}

.notice.matomo-whats-new h6 {
margin: 0;
font-style: italic;
color: #9D2235;
font-size: .8em;
}

.notice.matomo-whats-new h3 {
font-size: 1.6em;
margin: 6px 0;
}

.matomo-plugin-list.matomo-new-plugins .plugin-card {
position: relative;
}

.matomo-plugin-list.matomo-new-plugins .plugin-card .matomo-new-marker {
position: absolute;
right: 8px;
top: 8px;
font-style: italic;
color: #9D2235;
}
3 changes: 3 additions & 0 deletions assets/img/crash_analytics_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,34 @@ window.jQuery(document).ready(function ($) {
});
});
}

// whats new notice dismiss
if (typeof mtmWhatsNewNotificationAjax !== 'undefined' && mtmWhatsNewNotificationAjax.ajax_url) {
$('body').on('click', '.matomo-whats-new .notice-dismiss', function (e) {
$.post(mtmWhatsNewNotificationAjax.ajax_url, {
_ajax_nonce: mtmWhatsNewNotificationAjax.nonce,
action: 'mtm_dismiss_whats_new',
matomo_notification: $(e.target).closest('.matomo-whats-new').data('notification-id'),
});
});
}

// add a notification dot to menu items that need it (see WhatsNewNotification.php)
if (typeof mtmUnseenWhatsNewNotifications !== 'undefined' && mtmUnseenWhatsNewNotifications.length) {
$('#toplevel_page_matomo a').each(function () {
var href = $(this).attr('href');

var m = href.match(/\?page=(.*?)$/);
var page = m && m[1];
if (!page) {
return;
}

if (!mtmUnseenWhatsNewNotifications.includes(page)) {
return;
}

$(this).addClass('matomo-notification-dot');
});
}
});
11 changes: 11 additions & 0 deletions classes/WpMatomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public function __construct() {
$plugin_admin_overrides->register_hooks();
}

add_action(
'init',
function () {
$whats_new_notifications = new \WpMatomo\Admin\WhatsNewNotifications( self::$settings );
if ( $whats_new_notifications->is_active() ) {
$whats_new_notifications->register_hooks();
}
$whats_new_notifications->register_ajax();
}
);

$tracking_code = new TrackingCode( self::$settings );
$tracking_code->register_hooks();
$annotations = new Annotations( self::$settings );
Expand Down
7 changes: 5 additions & 2 deletions classes/WpMatomo/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public function __construct( $settings, $init_menu = true ) {
}

public static function is_matomo_admin() {
return isset( $_GET['page'] )
&& substr( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 0, 7 ) === 'matomo-';
return substr( self::get_current_page(), 0, 7 ) === 'matomo-';
}

public static function get_current_page() {
return isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
}

public function load_scripts() {
Expand Down
Loading