-
Notifications
You must be signed in to change notification settings - Fork 1
Fetaure: Add Analytics Admin Page, Navigation & Controls #203
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
Open
alaca
wants to merge
22
commits into
develop
Choose a base branch
from
feature/analytics-admin-page
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bb2b53c
initial commit
alaca 788e015
chore: fix eslint
alaca b2fc3b4
chore: fix eslint
alaca 4cf99c1
chore: formatting
alaca b907922
feature: add chart.umd.min.js
alaca 583086a
refactor: date handling and format
alaca 49c418c
feature: analytics test
alaca 7e39221
refactor: use proper css class, use include once
alaca 04d6ac0
refactor: implement copilot suggestion
alaca ed38519
refactor: copilot suggestion
alaca 0410267
refactor: update the styles to look more like in figma - needs more work
alaca dc88a3f
refactor: update test
alaca b7d2717
chore: formatting
alaca ee4b337
refactor: use Mailchimp_List_Subscribe_Form_Blocks class to get list
alaca 5b35917
Revert add submenu implementation.
iamdharmesh 5c48ef9
Update footer text on analytics page.
iamdharmesh 8d1a451
- Overall design improvements
iamdharmesh 328e992
Add datepicker.
iamdharmesh 9e6fa24
Fix set Date
iamdharmesh 09f2559
Apply suggestions from copilot
iamdharmesh 7501fd3
ignore chartjs from eslint.
iamdharmesh 1f3f392
Ignore "uncaught:exception" to prevent test from failing.
iamdharmesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /** | ||
| * Mailchimp Analytics Page Styles | ||
| * | ||
| * @package Mailchimp | ||
| */ | ||
|
|
||
| /* Filters bar */ | ||
| .mailchimp-sf-analytics-wrapper { | ||
| max-width: 1200px; | ||
| margin: 20px 0; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filters { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| align-items: flex-end; | ||
| gap: 16px; | ||
| padding: 20px; | ||
| background: #fff; | ||
| border: 1px solid #dcdcde; | ||
| border-radius: 4px; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filter-group { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 4px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filter-group label { | ||
| font-size: 12px; | ||
| font-weight: 600; | ||
| color: #1d2327; | ||
| text-transform: uppercase; | ||
| letter-spacing: 0.5px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filter-group select, | ||
| .mailchimp-sf-analytics-filter-group input[type="date"] { | ||
| min-width: 180px; | ||
| height: 36px; | ||
| padding: 0 8px; | ||
| border: 1px solid #8c8f94; | ||
| border-radius: 4px; | ||
| font-size: 14px; | ||
| color: #1d2327; | ||
| background-color: #fff; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filter-group select:focus, | ||
| .mailchimp-sf-analytics-filter-group input[type="date"]:focus { | ||
| border-color: #007cba; | ||
| box-shadow: 0 0 0 1px #007cba; | ||
| outline: none; | ||
| } | ||
|
|
||
| /* Custom date range row */ | ||
| .mailchimp-sf-custom-dates { | ||
| flex-direction: row; | ||
| align-items: flex-end; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .mailchimp-sf-custom-dates label { | ||
| align-self: center; | ||
| } | ||
|
|
||
| /* Resolved date range display */ | ||
| .mailchimp-sf-analytics-date-display { | ||
| margin-left: auto; | ||
| align-self: center; | ||
| font-size: 14px; | ||
| color: #50575e; | ||
| font-style: italic; | ||
| } | ||
|
|
||
| /* Content area */ | ||
| .mailchimp-sf-analytics-content { | ||
| padding: 24px; | ||
| background: #fff; | ||
| border: 1px solid #dcdcde; | ||
| border-radius: 4px; | ||
| min-height: 200px; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-placeholder { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| min-height: 200px; | ||
| color: #8c8f94; | ||
| font-size: 15px; | ||
| } | ||
|
|
||
| /* Deep link */ | ||
| .mailchimp-sf-analytics-deep-link { | ||
| margin-top: 16px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-deep-link a { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 6px; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-deep-link .dashicons { | ||
| font-size: 16px; | ||
| width: 16px; | ||
| height: 16px; | ||
| line-height: 16px; | ||
| } | ||
|
|
||
| /* Responsive */ | ||
| @media screen and (max-width: 782px) { | ||
| .mailchimp-sf-analytics-filters { | ||
| flex-direction: column; | ||
| align-items: stretch; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-date-display { | ||
| margin-left: 0; | ||
| } | ||
|
|
||
| .mailchimp-sf-custom-dates { | ||
| flex-direction: column; | ||
| align-items: stretch; | ||
| } | ||
|
|
||
| .mailchimp-sf-analytics-filter-group select, | ||
| .mailchimp-sf-analytics-filter-group input[type="date"] { | ||
| min-width: auto; | ||
| width: 100%; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * Mailchimp Analytics Page JavaScript | ||
| * | ||
| * @package Mailchimp | ||
| */ | ||
|
|
||
| (function () { | ||
| const dateRangeSelect = document.getElementById('mailchimp-sf-date-range'); | ||
| const customDates = document.querySelector('.mailchimp-sf-custom-dates'); | ||
| const dateFrom = document.getElementById('mailchimp-sf-date-from'); | ||
| const dateTo = document.getElementById('mailchimp-sf-date-to'); | ||
| const listFilter = document.getElementById('mailchimp-sf-list-filter'); | ||
| const resolvedDisplay = document.getElementById('mailchimp-sf-resolved-date-range'); | ||
|
|
||
| /** | ||
| * Format a Date object to a human-readable string. | ||
| * | ||
| * @param {Date} date Date to format. | ||
| * @returns {string} Formatted date string. | ||
| */ | ||
| function formatDate(date) { | ||
| return date.toLocaleDateString(undefined, { | ||
| year: 'numeric', | ||
| month: 'short', | ||
| day: 'numeric', | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get the resolved date range based on current filter selection. | ||
| * | ||
| * @returns {{ from: Date, to: Date }|null} Date range or null. | ||
| */ | ||
| function getDateRange() { | ||
| const { value } = dateRangeSelect; | ||
| let to = new Date(); | ||
| let from; | ||
|
|
||
| if (value === 'custom') { | ||
| if (!dateFrom.value || !dateTo.value) { | ||
| return null; | ||
| } | ||
| from = new Date(`${dateFrom.value}T00:00:00`); | ||
| to = new Date(`${dateTo.value}T23:59:59`); | ||
| return { from, to }; | ||
| } | ||
|
|
||
| const days = parseInt(value, 10); | ||
| from = new Date(); | ||
| from.setDate(from.getDate() - days); | ||
| return { from, to }; | ||
| } | ||
|
|
||
| /** | ||
| * Update the resolved date range display text. | ||
| */ | ||
| function updateResolvedDateRange() { | ||
| const range = getDateRange(); | ||
| if (range) { | ||
| resolvedDisplay.textContent = `${formatDate(range.from)} \u2013 ${formatDate(range.to)}`; | ||
| } else { | ||
| resolvedDisplay.textContent = ''; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Toggle visibility of custom date inputs. | ||
| */ | ||
| function toggleCustomDates() { | ||
| const isCustom = dateRangeSelect.value === 'custom'; | ||
| customDates.style.display = isCustom ? 'flex' : 'none'; | ||
| } | ||
alaca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Refresh analytics sections when filters change. | ||
| */ | ||
| function refreshAnalytics() { | ||
| updateResolvedDateRange(); | ||
|
|
||
| const range = getDateRange(); | ||
| const listId = listFilter ? listFilter.value : ''; | ||
|
|
||
| if (!range) { | ||
| return; | ||
| } | ||
|
|
||
| // Dispatch a custom event so other scripts can listen for filter changes. | ||
| const event = new CustomEvent('mailchimp-analytics-refresh', { | ||
| detail: { | ||
| from: range.from.toISOString(), | ||
| to: range.to.toISOString(), | ||
| listId, | ||
| }, | ||
alaca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| document.dispatchEvent(event); | ||
| } | ||
|
|
||
| // Bind events. | ||
| if (dateRangeSelect) { | ||
| dateRangeSelect.addEventListener('change', function () { | ||
| toggleCustomDates(); | ||
| refreshAnalytics(); | ||
| }); | ||
| } | ||
|
|
||
| if (dateFrom) { | ||
| dateFrom.addEventListener('change', refreshAnalytics); | ||
| } | ||
|
|
||
| if (dateTo) { | ||
| dateTo.addEventListener('change', refreshAnalytics); | ||
| } | ||
|
|
||
| if (listFilter) { | ||
| listFilter.addEventListener('change', refreshAnalytics); | ||
| } | ||
|
|
||
| // Initialize on load. | ||
| toggleCustomDates(); | ||
| updateResolvedDateRange(); | ||
| })(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <?php | ||
| /** | ||
| * Analytics page template | ||
| * | ||
| * @package Mailchimp | ||
| */ | ||
|
|
||
| $user = get_option( 'mc_user' ); | ||
| $is_logged_in = ! ( ! $user || ( ! get_option( 'mc_api_key' ) && ! mailchimp_sf_get_access_token() ) ); | ||
alaca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $lists = get_option( 'mailchimp_sf_lists', array() ); | ||
iamdharmesh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $current_list = get_option( 'mc_list_id', '' ); | ||
| $dc = get_option( 'mc_datacenter', '' ); | ||
| ?> | ||
| <div id="mailchimp-sf-analytics-page"> | ||
| <?php require_once MCSF_DIR . 'includes/admin/templates/header.php'; ?> | ||
alaca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <div class="mailchimp-sf-settings-page-hero-wrapper"> | ||
| <div class="mailchimp-sf-settings-page-hero"> | ||
| <div class="mailchimp-sf-settings-page-hero-title-wrapper"> | ||
| <h1 class="mailchimp-sf-settings-page-hero-title"> | ||
| <?php esc_html_e( 'Analytics', 'mailchimp' ); ?> | ||
| </h1> | ||
| <p class="mailchimp-sf-settings-page-hero-description"> | ||
| <?php esc_html_e( 'View audience analytics and insights for your Mailchimp lists.', 'mailchimp' ); ?> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="wrap"> | ||
| <div class="mailchimp-sf-analytics-wrapper"> | ||
| <div class="mailchimp-sf-analytics-filters"> | ||
| <div class="mailchimp-sf-analytics-filter-group"> | ||
| <label for="mailchimp-sf-date-range"><?php esc_html_e( 'Date Range', 'mailchimp' ); ?></label> | ||
| <select id="mailchimp-sf-date-range"> | ||
alaca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <option value="7"><?php esc_html_e( 'Last 7 days', 'mailchimp' ); ?></option> | ||
| <option value="30" selected><?php esc_html_e( 'Last 30 days', 'mailchimp' ); ?></option> | ||
| <option value="90"><?php esc_html_e( 'Last 90 days', 'mailchimp' ); ?></option> | ||
| <option value="180"><?php esc_html_e( 'Last 6 months', 'mailchimp' ); ?></option> | ||
| <option value="365"><?php esc_html_e( 'Last year', 'mailchimp' ); ?></option> | ||
| <option value="custom"><?php esc_html_e( 'Custom', 'mailchimp' ); ?></option> | ||
| </select> | ||
| </div> | ||
|
|
||
| <div class="mailchimp-sf-analytics-filter-group mailchimp-sf-custom-dates" style="display: none;"> | ||
| <label for="mailchimp-sf-date-from"><?php esc_html_e( 'From', 'mailchimp' ); ?></label> | ||
| <input type="date" id="mailchimp-sf-date-from" /> | ||
| <label for="mailchimp-sf-date-to"><?php esc_html_e( 'To', 'mailchimp' ); ?></label> | ||
| <input type="date" id="mailchimp-sf-date-to" /> | ||
| </div> | ||
|
|
||
| <div class="mailchimp-sf-analytics-filter-group"> | ||
| <label for="mailchimp-sf-list-filter"><?php esc_html_e( 'List', 'mailchimp' ); ?></label> | ||
| <select id="mailchimp-sf-list-filter"> | ||
| <?php if ( ! empty( $lists ) ) : ?> | ||
| <?php foreach ( $lists as $list ) : ?> | ||
| <option value="<?php echo esc_attr( $list['id'] ); ?>" <?php selected( $list['id'], $current_list ); ?>> | ||
| <?php echo esc_html( $list['name'] ); ?> | ||
| </option> | ||
| <?php endforeach; ?> | ||
| <?php endif; ?> | ||
| </select> | ||
| </div> | ||
|
|
||
| <div class="mailchimp-sf-analytics-date-display"> | ||
| <span id="mailchimp-sf-resolved-date-range"></span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="mailchimp-sf-analytics-content" id="mailchimp-sf-analytics-content"> | ||
| <div class="mailchimp-sf-analytics-placeholder"> | ||
| <p><?php esc_html_e( 'Select a date range and list to view analytics.', 'mailchimp' ); ?></p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <?php if ( $dc ) : ?> | ||
| <div class="mailchimp-sf-analytics-deep-link"> | ||
| <a href="<?php echo esc_url( 'https://' . $dc . '.admin.mailchimp.com/analytics/audience-analytics/' ); ?>" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| class="mailchimp-sf-button btn-secondary"> | ||
| <?php esc_html_e( 'View detailed analytics in Mailchimp', 'mailchimp' ); ?> | ||
| <span class="dashicons dashicons-external" aria-hidden="true"></span> | ||
| </a> | ||
| </div> | ||
| <?php endif; ?> | ||
| </div> | ||
| </div> | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.