Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
5fc6c69
First stab at settings screen.
Dan0sz Jun 21, 2026
dcfb62b
Fixed: add main WP domain to Language Domains list.
Dan0sz Jun 22, 2026
f1ac183
Fixed: validate both fields before updating Connect button status.
Dan0sz Jun 22, 2026
0e905a1
Fixed: Domain Name en API token are now always stored as an array.
Dan0sz Jun 22, 2026
225dee4
Added Language Domains label.
Dan0sz Jun 22, 2026
33ce5d7
This isn't a form, so this isn't required.
Dan0sz Jun 22, 2026
a3aa917
Re-factor element names to be more appropriate for their new purpose.
Dan0sz Jun 22, 2026
353862e
Deduplicated JS code.
Dan0sz Jun 22, 2026
1c62907
Minor refactor.
Dan0sz Jun 22, 2026
e095cf2
Fixed: properly display "connect" status in button, when API token or…
Dan0sz Jun 22, 2026
6cfd9a2
Fixed: spinner display when connecting.
Dan0sz Jun 22, 2026
24c5b47
Improved: Display language domain as default domain name initially.
Dan0sz Jun 22, 2026
08f04ca
Improved: added mt-1 to the pulldown menu.
Dan0sz Jun 22, 2026
c0156ac
Fixed: couldn't create plugin token for other than default language d…
Dan0sz Jun 22, 2026
981bbc0
Fixed: make sure JS files are stored per domain.
Dan0sz Jun 23, 2026
50f3fdf
Fixed: Provisioning
Dan0sz Jun 23, 2026
0a9e3a0
Fixed: provisioning for ecommerce plugins.
Dan0sz Jun 23, 2026
b5f56d3
Fixed: provisioning for ecommerce plugins.
Dan0sz Jun 23, 2026
950dde4
Fixed: token validation caching for multiple tokens.
Dan0sz Jun 23, 2026
db6e9fe
Merge branch 'develop' into wpml_compatibility
Dan0sz Jun 23, 2026
15b33bf
Fixed: Provisioning would only create goals on the last domain, due t…
Dan0sz Jun 24, 2026
fcb0a7c
Fixed: goals weren't created on fresh installs.
Dan0sz Jun 24, 2026
e663b38
Improved: added a cache layer to get_clients to improve API performance.
Dan0sz Jun 24, 2026
4086a39
Fixed: goals weren't created when tracker script config was updated.
Dan0sz Jun 24, 2026
e1d0f6c
Fixed tests.
Dan0sz Jun 24, 2026
0825413
PHPDoc.
Dan0sz Jun 24, 2026
75d70f6
Minor rearranging.
Dan0sz Jun 24, 2026
16ffce3
Improved: if provision_on_connect has run, don't run maybe_provision_…
Dan0sz Jun 24, 2026
af7188e
Fixed: tracker_script_config needs to be reset, before submitting our…
Dan0sz Jun 24, 2026
8e0eab5
Disable the reset for now, we might delete this later.
Dan0sz Jun 29, 2026
df0bad5
Improved: Wizard now only configures the main domain. Language Domain…
Dan0sz Jun 29, 2026
96a0b0c
Fixed: Create Token link didn't work in the slide.
Dan0sz Jun 29, 2026
16de7ba
Added: a dismissable notice that notifies WPML users, using the domai…
Dan0sz Jun 29, 2026
6efae24
Clean-up legacy code.
Dan0sz Jun 29, 2026
18e6eef
Separate global admin-js from the rest.
Dan0sz Jun 29, 2026
a18fa37
Updated multilang notice copy.
Dan0sz Jun 30, 2026
53fb5da
Updated multilang notice copy.
Dan0sz Jun 30, 2026
ccf1b77
Fixed: attach dismiss event listener to document, because the .notice…
Dan0sz Jun 30, 2026
2712c7f
Typo.
Dan0sz Jun 30, 2026
abdda4a
Minor refactor.
Dan0sz Jun 30, 2026
df323c2
Use option instead of user meta.
Dan0sz Jun 30, 2026
7898c01
Fixed: Load the saved domain map before applying the fallback.
Dan0sz Jun 30, 2026
8de6733
Fixed: The API-token wizard step is no longer gated.
Dan0sz Jun 30, 2026
6165d4e
Fixed: Don't treat unresolved per-domain paths as a successful download.
Dan0sz Jun 30, 2026
b3eb269
Fixed: Store the default language domain as a hostname, not home_url().
Dan0sz Jun 30, 2026
0dcb432
These tests are useless.
Dan0sz Jun 30, 2026
3d8d121
Fixed: The reflected method name is wrong.
Dan0sz Jun 30, 2026
2a59a88
Fixed: Don't merge numeric-keyed lists with the stored value.
Dan0sz Jun 30, 2026
e9dbd0d
Fixed: Use the api_token key as the forced language-domain context.
Dan0sz Jun 30, 2026
c3c9f2c
Typo.
Dan0sz Jun 30, 2026
d5b1379
Fixed: Normalize the transient before writing token entries.
Dan0sz Jun 30, 2026
504af4b
Merge remote-tracking branch 'origin/wpml_compatibility' into wpml_co…
Dan0sz Jun 30, 2026
368f6d1
Fixed tests.
Dan0sz Jun 30, 2026
c7efe14
Fixed tests.
Dan0sz Jul 1, 2026
19ebfb9
Fixed tests.
Dan0sz Jul 1, 2026
a7e135a
Fixed: Guard the nonce lookup before verification.
Dan0sz Jul 1, 2026
353b8d2
Fixed: Per-domain shared links are being collapsed into one stored va…
Dan0sz Jul 1, 2026
4a49b56
Fixed: Use the keyed token check for the dashboard toggle too.
Dan0sz Jul 1, 2026
5fe49b9
Remove unused code.
Dan0sz Jul 1, 2026
9533a6d
Ignore this code.
Dan0sz Jul 1, 2026
c0c81ae
Added Multilang Ajax option test.
Dan0sz Jul 1, 2026
1301b01
Fixed test.
Dan0sz Jul 2, 2026
d0d9098
Ignore this code.
Dan0sz Jul 2, 2026
4aa5265
Added tests.
Dan0sz Jul 2, 2026
8ee473e
Fixed tests.
Dan0sz Jul 2, 2026
6441994
Improved: normalize enhanced_measurements.
Dan0sz Jul 2, 2026
c8f1132
Fixed: undefined array key errors when updating settings with partial…
Dan0sz Jul 2, 2026
46115fe
Improved: Persist capabilities using the client’s domain key
Dan0sz Jul 2, 2026
f04c8d3
Improved: Register update hooks before clients exist.
Dan0sz Jul 2, 2026
583d602
Fixed tests.
Dan0sz Jul 2, 2026
006f416
Fixed tests.
Dan0sz Jul 2, 2026
0e2324e
Added: language domain stats are now available from the admin bar menu.
Dan0sz Jul 2, 2026
6fe5394
Fixed tests.
Dan0sz Jul 2, 2026
c50b6e4
added tests.
Dan0sz Jul 2, 2026
84d3f24
Added: plausible_analytics_admin_bar_view_analytics filter.
Dan0sz Jul 2, 2026
d5d98df
Ignore this code.
Dan0sz Jul 2, 2026
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
127 changes: 92 additions & 35 deletions assets/src/js/admin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
* Admin JS
*/
document.addEventListener('DOMContentLoaded', () => {
if (!document.location.href.includes('plausible_analytics')) {
return;
}

let plausible = {
/**
* Properties
*/
nonceElem: document.getElementById('_wpnonce'),
nonce: '',
showWizardElem: document.getElementById('show_wizard'),
domainNameElem: document.getElementById('domain_name'),
apiTokenElem: document.getElementById('api_token'),
createAPITokenElems: document.getElementsByClassName('plausible-create-api-token'),
buttonElems: document.getElementsByClassName('plausible-analytics-button'),
stepElems: document.getElementsByClassName('plausible-analytics-wizard-next-step'),
credentialsInputs: document.querySelectorAll('.plausible-analytics-credentials input'),
languageDomainPulldown: document.getElementById('language_domain'),
connectButtons: document.querySelectorAll('.plausible-analytics-credentials .plausible-analytics-connect-button'),

/**
* Bind events.
Expand All @@ -41,14 +38,6 @@ document.addEventListener('DOMContentLoaded', () => {
this.showWizardElem.addEventListener('click', this.showWizard);
}

if (this.domainNameElem !== null) {
this.domainNameElem.addEventListener('keyup', this.disableConnectButton);
}

if (this.apiTokenElem !== null) {
this.apiTokenElem.addEventListener('keyup', this.disableConnectButton);
}

if (this.createAPITokenElems.length > 0) {
for (let i = 0; i < this.createAPITokenElems.length; i++) {
this.createAPITokenElems[i].addEventListener('click', this.createAPIToken);
Expand Down Expand Up @@ -77,6 +66,22 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

if (this.credentialsInputs.length > 0) {
for (let i = 0; i < this.credentialsInputs.length; i++) {
this.credentialsInputs[i].addEventListener('keyup', this.disableConnectButton);
}
}

if (this.languageDomainPulldown !== null) {
this.languageDomainPulldown.addEventListener('change', this.switchLanguageDomain);
}

if (this.connectButtons.length > 0) {
for (let i = 0; i < this.connectButtons.length; i++) {
this.connectButtons[i].addEventListener('click', this.saveOption);
}
}

/**
* Run once on pageload.
*/
Expand Down Expand Up @@ -348,14 +353,15 @@ document.addEventListener('DOMContentLoaded', () => {
},

/**
* Save value of input or text area to DB.
* Save the value of the input or text area to DB.
*
* @param e
*/
saveOption: function (e) {
const button = e.target;
const section = button.closest('.plausible-analytics-section');
const inputs = section.querySelectorAll('input, textarea');
const button = e.target.closest('button');
const isCredentials = button.closest('.plausible-analytics-credentials');
const section = isCredentials || button.closest('.plausible-analytics-section');
const inputs = section.querySelectorAll(isCredentials ? 'input' : 'input, textarea');
const form = new FormData();
let options = [];

Expand All @@ -369,15 +375,35 @@ document.addEventListener('DOMContentLoaded', () => {
form.append('options', JSON.stringify(options));
form.append('_nonce', plausible.nonce);

if (button.children.length > 0) {
button.children[0].classList.remove('hidden');
let spinner = button.querySelector('svg');

if (spinner) {
spinner.classList.remove('hidden');
}

button.setAttribute('disabled', 'disabled');

plausible.ajax(form, button);
},

/**
* Switch Language Domain.
*
* @param e
*/
switchLanguageDomain: function (e) {
const selectedKey = e.target.value;
const credentials = document.querySelectorAll('.plausible-analytics-credentials');

credentials.forEach(function (credentialsSet) {
if (credentialsSet.dataset.languageDomainKey === selectedKey) {
credentialsSet.classList.remove('hidden');
} else {
credentialsSet.classList.add('hidden');
}
});
},

/**
* Disable options based on the capabilities retrieved from the API.
*
Expand Down Expand Up @@ -413,7 +439,7 @@ document.addEventListener('DOMContentLoaded', () => {
*/
validateInput: function (input) {
// Strip http(s)://(www.) from domain_name before sending it.
if (input.name === 'domain_name' && input.value.match(/^(https?:\/\/)?(www.)?/).length > 0) {
if ((input.name === 'domain_name' || input.name.startsWith('domain_name[')) && input.value.match(/^(https?:\/\/)?(www.)?/).length > 0) {
input.value = input.value.replace(/^(https?:\/\/)?(www.)?/, '');
}

Expand Down Expand Up @@ -461,21 +487,39 @@ document.addEventListener('DOMContentLoaded', () => {
},

/**
* Disable Connect button if Domain Name or API Token field is empty.
* Disable the Connect button if the Domain Name or API Token field is empty.
*
* @param e
*/
disableConnectButton: function (e) {
let target = e.target;
let button = document.getElementById('connect_plausible_analytics');
let credentials = target.closest('.plausible-analytics-credentials');
let button;
let buttonIsHref = false;

if (button === null) {
let slide_id = document.location.hash;
button = document.querySelector(slide_id + ' .plausible-analytics-wizard-next-step');
buttonIsHref = true;
if (credentials !== null) {
button = credentials.querySelector('.plausible-analytics-connect-button');
let allFilled = Array.from(credentials.querySelectorAll('input')).every(input => input.value.trim() !== '');

if (button === null) {
return;
}

button.disabled = !allFilled;

button.childNodes.forEach(function (node) {
if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() === plausible_analytics_i18n.connected) {
node.textContent = ' ' + plausible_analytics_i18n.connect;
}
});

return;
}

let slide_id = document.location.hash;
button = document.querySelector(slide_id + ' .plausible-analytics-wizard-next-step');
buttonIsHref = true;

if (button === null) {
return;
}
Expand All @@ -485,18 +529,18 @@ document.addEventListener('DOMContentLoaded', () => {
button.disabled = false;
} else {
button.classList.remove('pointer-events-none');
button.classList.replace('bg-gray-200', 'bg-indigo-600')
button.classList.replace('bg-gray-200', 'bg-indigo-600');
}

return;
}

if (!buttonIsHref) {
button.disabled = true;
button.innerHTML = button.innerHTML.replace('Connected', 'Connect');
button.textContent = button.textContent.replace('Connected', 'Connect');
} else {
button.classList += ' pointer-events-none';
button.classList.replace('bg-indigo-600', 'bg-gray-200')
button.classList.replace('bg-indigo-600', 'bg-gray-200');
}
},

Expand All @@ -508,7 +552,13 @@ document.addEventListener('DOMContentLoaded', () => {
createAPIToken: function (e) {
e.preventDefault();

let domain = document.getElementById('domain_name').value;
let domainElem = document.querySelector('.plausible-analytics-credentials:not(.hidden) [id^="domain_name"]');

if (domainElem === null) {
domainElem = document.querySelector('input[id^="domain_name"]');
}

let domain = domainElem ? domainElem.value : '';
domain = domain.replaceAll('/', '%2F');

window.open(`${plausible_analytics_hosted_domain}/${domain}/settings/integrations?new_token=WordPress`, '_blank', 'location=yes,height=768,width=1024,scrollbars=yes,status=no');
Expand Down Expand Up @@ -610,17 +660,24 @@ document.addEventListener('DOMContentLoaded', () => {
).then(response => {
if (button) {
if (button.children.length > 0) {
button.children[0].classList += ' hidden';
let spinner = button.querySelector('svg');
if (spinner) {
spinner.classList.add('hidden');
}
}

if (button.id === 'connect_plausible_analytics' && response.status === 200) {
button.innerText = plausible_analytics_i18n.connected;
if (button.classList.contains('plausible-analytics-connect-button') && response.status === 200) {
button.childNodes.forEach(function (node) {
if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() !== '') {
node.textContent = ' ' + plausible_analytics_i18n.connected;
}
});
} else {
button.removeAttribute('disabled');
}
}

// We still want the data, if it's a Payment Required error.
// We still want the data if it's a Payment Required error.
if (response.status === 200 || response.status === 402) {
return response.json();
}
Expand Down
14 changes: 14 additions & 0 deletions assets/src/js/admin/notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('click', function (e) {
if (!e.target.closest('.plausible-analytics-multilang-notice .notice-dismiss')) {
return;
}

var form = new FormData();

form.append('action', 'plausible_analytics_dismiss_multilang_notice');
form.append('_nonce', plausible_analytics_notice.nonce);

fetch(ajaxurl, {method: 'POST', body: form});
});
});
Loading
Loading