diff --git a/assets/js/dashboard/mount.js b/assets/js/dashboard/mount.js index c1cac71d9..9c923a88b 100644 --- a/assets/js/dashboard/mount.js +++ b/assets/js/dashboard/mount.js @@ -17,6 +17,7 @@ if (container) { offset: container.dataset.offset, hasGoals: container.dataset.hasGoals === 'true', statsBegin: container.dataset.statsBegin, + nativeStatsBegin: container.dataset.nativeStatsBegin, embedded: container.dataset.embedded, background: container.dataset.background, isDbip: container.dataset.isDbip === 'true', diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.js index 89b4753cc..36193c672 100644 --- a/assets/js/dashboard/stats/graph/visitor-graph.js +++ b/assets/js/dashboard/stats/graph/visitor-graph.js @@ -13,6 +13,7 @@ import { IntervalPicker, getStoredInterval, storeInterval } from './interval-pic import FadeIn from '../../fade-in'; import * as url from '../../util/url' import classNames from 'classnames'; +import { parseNaiveDate, isBefore } from '../../util/date' const calculateMaximumY = function(dataset) { const yAxisValues = dataset @@ -284,9 +285,22 @@ class LineGraph extends React.Component { } importedNotice() { - const source = this.props.topStatData && this.props.topStatData.imported_source; + if (!this.props.topStatData?.imported_source) return - if (source) { + const isBeforeNativeStats = (date) => { + if (!date) return false + + const nativeStatsBegin = parseNaiveDate(this.props.site.nativeStatsBegin) + const parsedDate = parseNaiveDate(date) + + return isBefore(parsedDate, nativeStatsBegin, "day") + } + + const isQueryingImportedPeriod = isBeforeNativeStats(this.props.topStatData.from) + const isComparingImportedPeriod = isBeforeNativeStats(this.props.topStatData.comparing_from) + + if (isQueryingImportedPeriod || isComparingImportedPeriod) { + const source = this.props.topStatData.imported_source const withImported = this.props.topStatData.with_imported; const strike = withImported ? "" : " line-through" const target = url.setQuery('with_imported', !withImported) diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex index 58174a3b3..74b4c2d69 100644 --- a/lib/plausible_web/controllers/stats_controller.ex +++ b/lib/plausible_web/controllers/stats_controller.ex @@ -65,6 +65,7 @@ defmodule PlausibleWeb.StatsController do site: site, has_goals: Plausible.Sites.has_goals?(site), stats_start_date: stats_start_date, + native_stats_start_date: NaiveDateTime.to_date(site.native_stats_start_at), title: "Plausible · " <> site.domain, offer_email_report: offer_email_report, demo: demo, @@ -296,6 +297,7 @@ defmodule PlausibleWeb.StatsController do site: shared_link.site, has_goals: Sites.has_goals?(shared_link.site), stats_start_date: shared_link.site.stats_start_date, + native_stats_start_date: NaiveDateTime.to_date(shared_link.site.native_stats_start_at), title: "Plausible · " <> shared_link.site.domain, offer_email_report: false, demo: false, diff --git a/lib/plausible_web/templates/stats/stats.html.eex b/lib/plausible_web/templates/stats/stats.html.eex index 98e76cf3d..2d8d4c65c 100644 --- a/lib/plausible_web/templates/stats/stats.html.eex +++ b/lib/plausible_web/templates/stats/stats.html.eex @@ -20,6 +20,7 @@ data-has-goals="<%= @has_goals %>" data-logged-in="<%= !!@conn.assigns[:current_user] %>" data-stats-begin="<%= @stats_start_date %>" + data-native-stats-begin="<%= @native_stats_start_date %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>"