diff --git a/assets/src/js/admin/main.js b/assets/src/js/admin/main.js index 4378bca..f3b52dc 100644 --- a/assets/src/js/admin/main.js +++ b/assets/src/js/admin/main.js @@ -232,7 +232,7 @@ document.addEventListener('DOMContentLoaded', () => { let domain = document.getElementById('domain_name').value; domain = domain.replace('/', '%2F'); - window.open(`https://plausible.io/${domain}/settings/integrations?new_token=WordPress`, '_blank', 'location=yes,height=768,width=1024,scrollbars=yes,status=no'); + window.open(`${plausible_analytics_hosted_domain}/${domain}/settings/integrations?new_token=WordPress`, '_blank', 'location=yes,height=768,width=1024,scrollbars=yes,status=no'); }, /** diff --git a/assets/src/js/admin/main.min.js b/assets/src/js/admin/main.min.js new file mode 100644 index 0000000..04d91fa --- /dev/null +++ b/assets/src/js/admin/main.min.js @@ -0,0 +1 @@ +document.addEventListener("DOMContentLoaded",()=>{if(!document.location.href.includes("plausible_analytics")){return}let plausible={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"),init:function(){if(document.location.hash===""&&document.getElementById("plausible-analytics-wizard")!==null){document.location.hash="#welcome_slide"}if(this.nonceElem!==null){this.nonce=this.nonceElem.value}this.toggleWizardStep();window.addEventListener("hashchange",this.toggleWizardStep);if(this.showWizardElem!==null){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;i0){for(let i=0;i0){for(let i=0;in);if(currentlyCompletedSteps.length<1){return}currentlyCompletedSteps.forEach(function(step){let completedStep=document.getElementById("completed-step-"+step);let inactiveStep=document.getElementById("step-"+step);completedStep.classList.remove("hidden");inactiveStep.classList+=" hidden"})},ajax:function(data,button=null,showMessages=true){return fetch(ajaxurl,{method:"POST",body:data}).then(response=>{if(button){button.children[0].classList+=" hidden";button.removeAttribute("disabled")}if(response.status===200){return response.json()}return false}).then(response=>{if(showMessages===true){plausible.showMessages()}let event=new CustomEvent("plausibleAjaxDone",{detail:response});document.dispatchEvent(event);return response.data})},showMessages:function(){let messages=plausible.fetchMessages();messages.then(function(messages){if(messages.error!==false){plausible.showMessage(messages.error,"error")}else if(messages.notice!==false){plausible.showMessage(messages.notice,"notice")}else if(messages.success!==false){plausible.showMessage(messages.success,"success")}if(messages.additional.length===0||document.getElementById("plausible-analytics-wizard")!==null){return}if(messages.additional.id!==undefined&&messages.additional.message){plausible.showAdditionalMessage(messages.additional.message,messages.additional.id)}else if(messages.additional.id!==undefined&&messages.additional.message===""){plausible.removeAdditionalMessage(messages.additional.id)}})},fetchMessages:function(){let data=new FormData;data.append("action","plausible_analytics_messages");let result=plausible.ajax(data,null,false);return result.then(function(response){return response})},showMessage:function(message,type="success"){if(type==="error"){document.getElementById("icon-error").classList.remove("hidden");document.getElementById("icon-success").classList.add("hidden");document.getElementById("icon-notice").classList.add("hidden")}else if(type==="notice"){document.getElementById("icon-notice").classList.remove("hidden");document.getElementById("icon-error").classList.add("hidden");document.getElementById("icon-success").classList.add("hidden")}else{document.getElementById("icon-success").classList.remove("hidden");document.getElementById("icon-error").classList.add("hidden");document.getElementById("icon-notice").classList.add("hidden")}let notice=document.getElementById("plausible-analytics-notice");document.getElementById("plausible-analytics-notice-text").innerHTML=message;notice.classList.remove("hidden");setTimeout(function(){notice.classList.replace("opacity-0","opacity-100")},200);if(type!=="error"){setTimeout(function(){notice.classList.replace("opacity-100","opacity-0");setTimeout(function(){notice.classList+=" hidden"},200)},2e3)}},showAdditionalMessage:function(html,target){let targetElem=document.querySelector(`[name='${target}']`);let container=targetElem.closest(".plausible-analytics-group");container.innerHTML+=html},removeAdditionalMessage:function(target){let targetElem=document.querySelector(`[name="${target}"]`);let container=targetElem.closest(".plausible-analytics-group");let additionalMessage;if(container.children.length>0){for(let i=0;i - 1; ?> - 1 ); } - foreach ( $fields as $field ): ?> - - + ?> diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php index 1520747..6162af7 100644 --- a/src/Admin/Settings/Page.php +++ b/src/Admin/Settings/Page.php @@ -69,9 +69,7 @@ class Page extends API { public function __construct() { $this->init(); - $settings = Helpers::get_settings(); - $domain = Helpers::get_domain(); - $self_hosted_domain = defined( 'PLAUSIBLE_SELF_HOSTED_DOMAIN' ) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : $settings[ 'self_hosted_domain' ]; + $settings = Helpers::get_settings(); $this->fields = [ 'general' => [ @@ -87,14 +85,14 @@ public function __construct() { ), 'post' ), - 'https://plausible.io/sites' + Helpers::get_hosted_domain_url() . '/sites' ), 'fields' => [ [ 'label' => esc_html__( 'Domain name', 'plausible-analytics' ), 'slug' => 'domain_name', 'type' => 'text', - 'value' => $domain, + 'value' => Helpers::get_domain(), ], [ 'label' => esc_html__( 'API token', 'plausible-analytics' ), @@ -333,7 +331,8 @@ public function __construct() { 'label' => esc_html__( 'Domain name', 'plausible-analytics' ), 'slug' => 'self_hosted_domain', 'type' => 'text', - 'value' => $self_hosted_domain, + 'value' => defined( 'PLAUSIBLE_SELF_HOSTED_DOMAIN' ) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : + $settings[ 'self_hosted_domain' ], 'placeholder' => 'e.g. ' . Helpers::get_domain(), 'disabled' => Helpers::proxy_enabled(), ], @@ -368,8 +367,9 @@ public function __construct() { 'type' => 'text', 'value' => $settings[ 'self_hosted_shared_link' ], 'placeholder' => sprintf( - wp_kses( __( 'E.g. https://plausible.io/share/%s?auth=XXXXXXXXXXXX', 'plausible-analytics' ), 'post' ), - $domain + wp_kses( __( 'E.g. %s/share/%s?auth=XXXXXXXXXXXX', 'plausible-analytics' ), 'post' ), + Helpers::get_hosted_domain_url(), + Helpers::get_domain() ), 'disabled' => Helpers::proxy_enabled(), ], @@ -613,7 +613,7 @@ public function render_analytics_dashboard() { /** * Prior to this version, the default value would contain an example "auth" key, i.e. XXXXXXXXX. * When this option was saved to the database, underlying code would fail, throwing a CORS related error in browsers. - * Now, we explicitly check for the existence of this example "auth" key, and display a human readable error message to + * Now, we explicitly check for the existence of this example "auth" key, and display a human-readable error message to * those who haven't properly set it up. * * @since v1.2.5 @@ -630,12 +630,14 @@ public function render_analytics_dashboard() { if ( $shared_link && $page_url ) { $shared_link .= "&page={$page_url}"; } + + $hosted_domain = Helpers::get_hosted_domain_url(); ?>
- +