From 9e5d63ed96a7b1e49413f491435edd4a4eaf623c Mon Sep 17 00:00:00 2001 From: Vinicius Brasil Date: Wed, 3 Jan 2024 08:32:21 -0300 Subject: [PATCH] Display premium features tabs on the dashboard (#3646) * Display premium features tabs on the dashboard This commit makes the funnels and props tab on the dashboard visible even when the site owner's plan does not have access to that feature. This is to raise awareness of those features, and if the site owner does not want to see that tab, they can still click "Hide this report" to hide it. Previously, when the plan did not support a feature, the feature module `enabled/1` function returned `false`, regardless of the `sites.feature_enabled` toggle. This commit creates a new function called `opted_out/1` to differentiate access from explicitly opting out a feature. * Remove unused data-conversions-enabled attribute * DRY Plausible.Billing.Feature.check_availability/1 function * Allow opting out features the user doesn't have access to * add upgrade CTA to FeatureSetupNotice * fix JS linting errors * simplify notice.js * fix behaviour when deleting funnels saved to localstorage In case some other funnel exists, we will use that as the default selected one. If not, a feature setup notice will be displayed again. --------- Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Co-authored-by: Robert Joonas --- assets/js/dashboard.js | 8 +- assets/js/dashboard/components/notice.js | 14 ++-- assets/js/dashboard/stats/behaviours/index.js | 73 ++++++++++++++----- lib/plausible/billing/feature.ex | 46 +++++++----- .../controllers/stats_controller.ex | 2 + .../templates/stats/stats.html.eex | 8 +- test/plausible/billing/feature_test.exs | 19 ++++- 7 files changed, 120 insertions(+), 50 deletions(-) diff --git a/assets/js/dashboard.js b/assets/js/dashboard.js index e4e2fbcc7..c733c0905 100644 --- a/assets/js/dashboard.js +++ b/assets/js/dashboard.js @@ -16,10 +16,12 @@ if (container) { domain: container.dataset.domain, offset: container.dataset.offset, hasGoals: container.dataset.hasGoals === 'true', - conversionsEnabled: container.dataset.conversionsEnabled === 'true', - funnelsEnabled: container.dataset.funnelsEnabled === 'true', - propsEnabled: container.dataset.propsEnabled === 'true', hasProps: container.dataset.hasProps === 'true', + funnelsAvailable: container.dataset.funnelsAvailable === 'true', + propsAvailable: container.dataset.propsAvailable === 'true', + conversionsOptedOut: container.dataset.conversionsOptedOut === 'true', + funnelsOptedOut: container.dataset.funnelsOptedOut === 'true', + propsOptedOut: container.dataset.propsOptedOut === 'true', funnels: JSON.parse(container.dataset.funnels), statsBegin: container.dataset.statsBegin, nativeStatsBegin: container.dataset.nativeStatsBegin, diff --git a/assets/js/dashboard/components/notice.js b/assets/js/dashboard/components/notice.js index fd2d9876a..656c7abbe 100644 --- a/assets/js/dashboard/components/notice.js +++ b/assets/js/dashboard/components/notice.js @@ -2,7 +2,7 @@ import React from "react" import { sectionTitles } from "../stats/behaviours" import * as api from '../api' -export function FeatureSetupNotice({ site, feature, shortFeatureName, title, info, settingsLink, onHideAction }) { +export function FeatureSetupNotice({ site, feature, title, info, callToAction, onHideAction }) { const sectionTitle = sectionTitles[feature] const requestHideSection = () => { @@ -14,10 +14,10 @@ export function FeatureSetupNotice({ site, feature, shortFeatureName, title, inf } } - function setupButton() { + function renderCallToAction() { return ( - -

Set up {shortFeatureName}

+
+

{callToAction.action}

@@ -25,7 +25,7 @@ export function FeatureSetupNotice({ site, feature, shortFeatureName, title, inf ) } - function hideButton() { + function renderHideButton() { return (