analytics/priv/repo/seeds.exs

284 lines
8.3 KiB
Elixir
Raw Normal View History

2019-09-02 14:29:19 +03:00
# Script for populating the database. You can run it as:
#
# mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
# Plausible.Repo.insert!(%Plausible.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
user = Plausible.Factory.insert(:user, email: "user@plausible.test", password: "plausible")
native_stats_range =
Date.range(
Date.add(Date.utc_today(), -720),
Date.utc_today()
)
imported_stats_range =
Date.range(
Date.add(native_stats_range.first, -360),
Date.add(native_stats_range.first, -1)
)
long_random_paths =
for _ <- 1..100 do
l = Enum.random(40..300)
"/long/#{l}/path/#{String.duplicate("0x", l)}/end"
end
long_random_urls =
for path <- long_random_paths do
"https://dummy.site#{path}"
end
site =
Plausible.Factory.insert(:site,
domain: "dummy.site",
native_stats_start_at: NaiveDateTime.new!(native_stats_range.first, ~T[00:00:00]),
stats_start_date: NaiveDateTime.new!(imported_stats_range.first, ~T[00:00:00]),
memberships: [
Plausible.Factory.build(:site_membership, user: user, role: :owner),
Plausible.Factory.build(:site_membership,
user: Plausible.Factory.build(:user, name: "Arnold Wallaby"),
role: :viewer
)
]
)
Integrations Settings section (#3427) * Extend the Tokens context module * Extract GA Import to separate component * Extract Search Console settings to separate component * Remove Search Console from the router * Stop counting imported pageviews in general settings * Remove search console controller action * Add settings_integrations controller action * Fix remaining redirects * Add Integrations route * Replace SC sidebar item with Integrations * Update site controller tests * Implement Plugins API Tokens LV * Apply universal heroicon to docs info links * Add flash on token creation * Update CHANGELOG * Redirect to integrations upon forgetting GA import * Update moduledocs * Remove unnecessary wildcards * WIP: attempt at fixing broken oauth flow * Fix post-import redirect * Fixup missing attribute * Format * Seed random google auth * Use example.com for seeded e-mails * Tweak Google integrations layout * Remove dangling IO.inspect * Bugfix: copy to clipboard breaking LV form bindings * Update lib/plausible/plugins/api/tokens.ex Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update lib/plausible_web/controllers/site_controller.ex Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update lib/plausible_web/live/plugins/api/settings.ex Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible/plugins/api/tokens_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> --------- Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2023-10-18 15:01:17 +03:00
Plausible.Factory.insert(:google_auth,
user: user,
site: site,
property: "sc-domain:dummy.test",
expires: NaiveDateTime.add(NaiveDateTime.utc_now(), 3600)
)
# Plugins API: on dev environment, use "plausible-plugin-dev-seed-token" for "dummy.site" to authenticate
seeded_token = Plausible.Plugins.API.Token.generate("seed-token")
{:ok, _, _} =
Plausible.Plugins.API.Tokens.create(site, "plausible-plugin-dev-seed-token", seeded_token)
Implement backend core for funnels (#3023) * Implement Funnel schema * Implement Funnels context module lib/plausible/funnels.ex - restored from: dca93621 Mark Vini's suggestion applied 7d1eec75 Update lib/plausible/funnels.ex 028036ad Review comments b694ccd5 Express the guard nicely acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels aea4ebc4 Access Funnel min/max steps via the __using__/1 macro 51f0397d Implement deleting funnels cf228630 wip 1f6fe25d Add number of steps to funnels list 89f10ecb wip 950a18d9 Dirty funnel save e62bfce5 Refactor funnel result evaluation 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 7a88fe44 Outline basic error handling c8ae3eaf Move Funnels to StatsController and use base query 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip fbd14e23 Absolute dirty wip 3ddd15ad wip 34ceb3f5 dirty wip test/plausible_web/controllers/api/stats_controller/funnels_test.exs - restored from: 9b532273 Test funnel stats controller Co-authored-by: Uku Taht <uku.taht@gmail.com> * Update Goals implementation lib/plausible/goal/schema.ex - restored from: 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion fbd14e23 Absolute dirty wip lib/plausible/goals.ex - restored from: aea4ebc4 Access Funnel min/max steps via the __using__/1 macro a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion ebdc4333 Extend the prompt in case of funnel-goal deletion 950a18d9 Dirty funnel save f06c3fcf wip test/plausible/goals_test.exs - restored from: a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion dee5bc9e Fixup tests * Update seeds * Split funnel schema modules * Add moduledoc to Funnel schema * Update Funnel.Step moduledoc * Add typespecs to Plausible.Funnels * Implement Phoenix.HTML.Safe for Funnel schema * Fixup a test after ordering goals by desc:id test/plausible_web/controllers/api/stats_controller/conversions_test.exs - restored from: 26a493cb Fixup a test after ordering goals by desc:id * Annotate Goal schema with type t() * Reword schema module docs * Fix up typespecs * Stop tagging Funnels.get/2 result * Nuke Goals.by_id!/2 * Test Funnels module test/plausible/funnels_test.exs - restored from: b7a6d3ad ya, rly 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 51f0397d Implement deleting funnels 1f6fe25d Add number of steps to funnels list dee5bc9e Fixup tests 950a18d9 Dirty funnel save 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip 34ceb3f5 dirty wip Co-authored-by: Uku Taht <uku.taht@gmail.com> * Apply changes related to 242081e5 * Evaluate funnels through `Stats.funnel/3` entry point --------- Co-authored-by: Uku Taht <uku.taht@gmail.com>
2023-06-13 15:01:39 +03:00
{:ok, goal1} = Plausible.Goals.create(site, %{"page_path" => "/"})
{:ok, goal2} = Plausible.Goals.create(site, %{"page_path" => "/register"})
{:ok, goal3} = Plausible.Goals.create(site, %{"page_path" => "/login"})
{:ok, goal4} = Plausible.Goals.create(site, %{"event_name" => "Purchase", "currency" => "USD"})
{:ok, _goal5} = Plausible.Goals.create(site, %{"page_path" => Enum.random(long_random_paths)})
{:ok, outbound} = Plausible.Goals.create(site, %{"event_name" => "Outbound Link: Click"})
Implement backend core for funnels (#3023) * Implement Funnel schema * Implement Funnels context module lib/plausible/funnels.ex - restored from: dca93621 Mark Vini's suggestion applied 7d1eec75 Update lib/plausible/funnels.ex 028036ad Review comments b694ccd5 Express the guard nicely acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels aea4ebc4 Access Funnel min/max steps via the __using__/1 macro 51f0397d Implement deleting funnels cf228630 wip 1f6fe25d Add number of steps to funnels list 89f10ecb wip 950a18d9 Dirty funnel save e62bfce5 Refactor funnel result evaluation 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 7a88fe44 Outline basic error handling c8ae3eaf Move Funnels to StatsController and use base query 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip fbd14e23 Absolute dirty wip 3ddd15ad wip 34ceb3f5 dirty wip test/plausible_web/controllers/api/stats_controller/funnels_test.exs - restored from: 9b532273 Test funnel stats controller Co-authored-by: Uku Taht <uku.taht@gmail.com> * Update Goals implementation lib/plausible/goal/schema.ex - restored from: 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion fbd14e23 Absolute dirty wip lib/plausible/goals.ex - restored from: aea4ebc4 Access Funnel min/max steps via the __using__/1 macro a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion ebdc4333 Extend the prompt in case of funnel-goal deletion 950a18d9 Dirty funnel save f06c3fcf wip test/plausible/goals_test.exs - restored from: a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion dee5bc9e Fixup tests * Update seeds * Split funnel schema modules * Add moduledoc to Funnel schema * Update Funnel.Step moduledoc * Add typespecs to Plausible.Funnels * Implement Phoenix.HTML.Safe for Funnel schema * Fixup a test after ordering goals by desc:id test/plausible_web/controllers/api/stats_controller/conversions_test.exs - restored from: 26a493cb Fixup a test after ordering goals by desc:id * Annotate Goal schema with type t() * Reword schema module docs * Fix up typespecs * Stop tagging Funnels.get/2 result * Nuke Goals.by_id!/2 * Test Funnels module test/plausible/funnels_test.exs - restored from: b7a6d3ad ya, rly 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 51f0397d Implement deleting funnels 1f6fe25d Add number of steps to funnels list dee5bc9e Fixup tests 950a18d9 Dirty funnel save 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip 34ceb3f5 dirty wip Co-authored-by: Uku Taht <uku.taht@gmail.com> * Apply changes related to 242081e5 * Evaluate funnels through `Stats.funnel/3` entry point --------- Co-authored-by: Uku Taht <uku.taht@gmail.com>
2023-06-13 15:01:39 +03:00
{:ok, _funnel} =
Plausible.Funnels.create(site, "From homepage to login", [
%{"goal_id" => goal1.id},
%{"goal_id" => goal2.id},
%{"goal_id" => goal3.id}
])
put_random_time = fn
date, 0 ->
current_hour = Time.utc_now().hour
current_minute = Time.utc_now().minute
random_time = Time.new!(:rand.uniform(current_hour), :rand.uniform(current_minute - 1), 0)
date
|> NaiveDateTime.new!(random_time)
|> NaiveDateTime.truncate(:second)
date, _ ->
random_time = Time.new!(:rand.uniform(23), :rand.uniform(59), 0)
date
|> NaiveDateTime.new!(random_time)
|> NaiveDateTime.truncate(:second)
end
geolocations = [
[
country_code: "IT",
subdivision1_code: "IT-62",
subdivision2_code: "IT-RM",
city_geoname_id: 3_169_070
],
[
country_code: "EE",
subdivision1_code: "EE-37",
subdivision2_code: "EE-784",
city_geoname_id: 588_409
],
[
country_code: "BR",
subdivision1_code: "BR-SP",
subdivision2_code: "",
city_geoname_id: 3_448_439
],
[
country_code: "PL",
subdivision1_code: "PL-14",
subdivision2_code: "",
city_geoname_id: 756_135
],
[
country_code: "DE",
subdivision1_code: "DE-BE",
subdivision2_code: "",
city_geoname_id: 2_950_159
],
[
country_code: "US",
subdivision1_code: "US-CA",
subdivision2_code: "",
city_geoname_id: 5_391_959
],
[]
]
native_stats_range
|> Enum.with_index()
|> Enum.flat_map(fn {date, index} ->
Implement backend core for funnels (#3023) * Implement Funnel schema * Implement Funnels context module lib/plausible/funnels.ex - restored from: dca93621 Mark Vini's suggestion applied 7d1eec75 Update lib/plausible/funnels.ex 028036ad Review comments b694ccd5 Express the guard nicely acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels aea4ebc4 Access Funnel min/max steps via the __using__/1 macro 51f0397d Implement deleting funnels cf228630 wip 1f6fe25d Add number of steps to funnels list 89f10ecb wip 950a18d9 Dirty funnel save e62bfce5 Refactor funnel result evaluation 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 7a88fe44 Outline basic error handling c8ae3eaf Move Funnels to StatsController and use base query 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip fbd14e23 Absolute dirty wip 3ddd15ad wip 34ceb3f5 dirty wip test/plausible_web/controllers/api/stats_controller/funnels_test.exs - restored from: 9b532273 Test funnel stats controller Co-authored-by: Uku Taht <uku.taht@gmail.com> * Update Goals implementation lib/plausible/goal/schema.ex - restored from: 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion fbd14e23 Absolute dirty wip lib/plausible/goals.ex - restored from: aea4ebc4 Access Funnel min/max steps via the __using__/1 macro a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion ebdc4333 Extend the prompt in case of funnel-goal deletion 950a18d9 Dirty funnel save f06c3fcf wip test/plausible/goals_test.exs - restored from: a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion dee5bc9e Fixup tests * Update seeds * Split funnel schema modules * Add moduledoc to Funnel schema * Update Funnel.Step moduledoc * Add typespecs to Plausible.Funnels * Implement Phoenix.HTML.Safe for Funnel schema * Fixup a test after ordering goals by desc:id test/plausible_web/controllers/api/stats_controller/conversions_test.exs - restored from: 26a493cb Fixup a test after ordering goals by desc:id * Annotate Goal schema with type t() * Reword schema module docs * Fix up typespecs * Stop tagging Funnels.get/2 result * Nuke Goals.by_id!/2 * Test Funnels module test/plausible/funnels_test.exs - restored from: b7a6d3ad ya, rly 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 51f0397d Implement deleting funnels 1f6fe25d Add number of steps to funnels list dee5bc9e Fixup tests 950a18d9 Dirty funnel save 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip 34ceb3f5 dirty wip Co-authored-by: Uku Taht <uku.taht@gmail.com> * Apply changes related to 242081e5 * Evaluate funnels through `Stats.funnel/3` entry point --------- Co-authored-by: Uku Taht <uku.taht@gmail.com>
2023-06-13 15:01:39 +03:00
Enum.map(0..Enum.random(1..500), fn _ ->
geolocation = Enum.random(geolocations)
[
site_id: site.id,
hostname: site.domain,
timestamp: put_random_time.(date, index),
referrer_source: Enum.random(["", "Facebook", "Twitter", "DuckDuckGo", "Google"]),
browser: Enum.random(["Edge", "Chrome", "Safari", "Firefox", "Vivaldi"]),
browser_version: to_string(Enum.random(0..50)),
screen_size: Enum.random(["Mobile", "Tablet", "Desktop", "Laptop"]),
operating_system: Enum.random(["Windows", "macOS", "Linux"]),
operating_system_version: to_string(Enum.random(0..15)),
pathname:
Enum.random([
"/",
"/login",
"/settings",
"/register",
"/docs",
"/docs/1",
"/docs/2" | long_random_paths
]),
Implement backend core for funnels (#3023) * Implement Funnel schema * Implement Funnels context module lib/plausible/funnels.ex - restored from: dca93621 Mark Vini's suggestion applied 7d1eec75 Update lib/plausible/funnels.ex 028036ad Review comments b694ccd5 Express the guard nicely acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels aea4ebc4 Access Funnel min/max steps via the __using__/1 macro 51f0397d Implement deleting funnels cf228630 wip 1f6fe25d Add number of steps to funnels list 89f10ecb wip 950a18d9 Dirty funnel save e62bfce5 Refactor funnel result evaluation 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 7a88fe44 Outline basic error handling c8ae3eaf Move Funnels to StatsController and use base query 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip fbd14e23 Absolute dirty wip 3ddd15ad wip 34ceb3f5 dirty wip test/plausible_web/controllers/api/stats_controller/funnels_test.exs - restored from: 9b532273 Test funnel stats controller Co-authored-by: Uku Taht <uku.taht@gmail.com> * Update Goals implementation lib/plausible/goal/schema.ex - restored from: 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion fbd14e23 Absolute dirty wip lib/plausible/goals.ex - restored from: aea4ebc4 Access Funnel min/max steps via the __using__/1 macro a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion ebdc4333 Extend the prompt in case of funnel-goal deletion 950a18d9 Dirty funnel save f06c3fcf wip test/plausible/goals_test.exs - restored from: a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion dee5bc9e Fixup tests * Update seeds * Split funnel schema modules * Add moduledoc to Funnel schema * Update Funnel.Step moduledoc * Add typespecs to Plausible.Funnels * Implement Phoenix.HTML.Safe for Funnel schema * Fixup a test after ordering goals by desc:id test/plausible_web/controllers/api/stats_controller/conversions_test.exs - restored from: 26a493cb Fixup a test after ordering goals by desc:id * Annotate Goal schema with type t() * Reword schema module docs * Fix up typespecs * Stop tagging Funnels.get/2 result * Nuke Goals.by_id!/2 * Test Funnels module test/plausible/funnels_test.exs - restored from: b7a6d3ad ya, rly 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 51f0397d Implement deleting funnels 1f6fe25d Add number of steps to funnels list dee5bc9e Fixup tests 950a18d9 Dirty funnel save 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip 34ceb3f5 dirty wip Co-authored-by: Uku Taht <uku.taht@gmail.com> * Apply changes related to 242081e5 * Evaluate funnels through `Stats.funnel/3` entry point --------- Co-authored-by: Uku Taht <uku.taht@gmail.com>
2023-06-13 15:01:39 +03:00
user_id: Enum.random(1..1200)
]
|> Keyword.merge(geolocation)
|> then(&Plausible.Factory.build(:pageview, &1))
end)
end)
|> Plausible.TestUtils.populate_stats()
native_stats_range
|> Enum.with_index()
|> Enum.flat_map(fn {date, index} ->
Enum.map(0..Enum.random(1..50), fn _ ->
geolocation = Enum.random(geolocations)
[
name: goal4.event_name,
site_id: site.id,
hostname: site.domain,
timestamp: put_random_time.(date, index),
referrer_source: Enum.random(["", "Facebook", "Twitter", "DuckDuckGo", "Google"]),
browser: Enum.random(["Edge", "Chrome", "Safari", "Firefox", "Vivaldi"]),
browser_version: to_string(Enum.random(0..50)),
screen_size: Enum.random(["Mobile", "Tablet", "Desktop", "Laptop"]),
operating_system: Enum.random(["Windows", "macOS", "Linux"]),
operating_system_version: to_string(Enum.random(0..15)),
pathname:
Enum.random([
"/",
"/login",
"/settings",
"/register",
"/docs",
"/docs/1",
"/docs/2" | long_random_paths
]),
user_id: Enum.random(1..1200),
revenue_reporting_amount: Decimal.new(Enum.random(100..10000)),
revenue_reporting_currency: "USD"
]
|> Keyword.merge(geolocation)
|> then(&Plausible.Factory.build(:event, &1))
end)
end)
|> Plausible.TestUtils.populate_stats()
native_stats_range
|> Enum.with_index()
|> Enum.flat_map(fn {date, index} ->
Enum.map(0..Enum.random(1..50), fn _ ->
geolocation = Enum.random(geolocations)
[
name: outbound.event_name,
site_id: site.id,
hostname: site.domain,
timestamp: put_random_time.(date, index),
referrer_source: Enum.random(["", "Facebook", "Twitter", "DuckDuckGo", "Google"]),
browser: Enum.random(["Edge", "Chrome", "Safari", "Firefox", "Vivaldi"]),
browser_version: to_string(Enum.random(0..50)),
screen_size: Enum.random(["Mobile", "Tablet", "Desktop", "Laptop"]),
operating_system: Enum.random(["Windows", "macOS", "Linux"]),
operating_system_version: to_string(Enum.random(0..15)),
user_id: Enum.random(1..1200),
Props Settings UI to match Goals Settings (#3322) * Add hint to creatable ComboBoxes without suggestions available * Load external resources once in funnel settings * Load external resources once in goal settings * Make Custom Props Settings UI match Goal Settings * Remove unnecessary goals query This should be done only once in the live view * Remove funnels feature flag * fixup * Make the modal scrollable * By default, focus first suggestion for creatables * Add sample props to seeds * Load all suggestions asynchronously, unless `Mix.env == :test` * ComboBox: Fix inconsistent suggestions We require "Create ..." element to be only focused when there are no suggestions available. This causes some issues, depending on the state, the least focusable index might be either 0 ("Create...") or 1. This patch addresses all the quirks with focus. * Fix ComboBox max results message So that AlpineJS doesn't think it's a focusable option. * Keep the state up to date when changing props * Update seeds with sensible prop names * Make escape work for closing combobox suggestions Co-authored-by: Uku Taht <Uku.taht@gmail.com> * Revert "Make escape work for closing combobox suggestions" This reverts commit 306866d2a15d652eaa0327f1b96a302de5e426e5. @ukutaht unfortunately this makes it impossible to select an suggestion. * Revert "Revert "Make escape work for closing combobox suggestions"" This reverts commit 4844857812d21ea1233fe3b9ae6f95364c945a14. * Make ESC great again * Improve readability --------- Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2023-09-13 15:55:29 +03:00
"meta.key": ["url", "logged_in", "is_customer", "amount"],
"meta.value": [
Props Settings UI to match Goals Settings (#3322) * Add hint to creatable ComboBoxes without suggestions available * Load external resources once in funnel settings * Load external resources once in goal settings * Make Custom Props Settings UI match Goal Settings * Remove unnecessary goals query This should be done only once in the live view * Remove funnels feature flag * fixup * Make the modal scrollable * By default, focus first suggestion for creatables * Add sample props to seeds * Load all suggestions asynchronously, unless `Mix.env == :test` * ComboBox: Fix inconsistent suggestions We require "Create ..." element to be only focused when there are no suggestions available. This causes some issues, depending on the state, the least focusable index might be either 0 ("Create...") or 1. This patch addresses all the quirks with focus. * Fix ComboBox max results message So that AlpineJS doesn't think it's a focusable option. * Keep the state up to date when changing props * Update seeds with sensible prop names * Make escape work for closing combobox suggestions Co-authored-by: Uku Taht <Uku.taht@gmail.com> * Revert "Make escape work for closing combobox suggestions" This reverts commit 306866d2a15d652eaa0327f1b96a302de5e426e5. @ukutaht unfortunately this makes it impossible to select an suggestion. * Revert "Revert "Make escape work for closing combobox suggestions"" This reverts commit 4844857812d21ea1233fe3b9ae6f95364c945a14. * Make ESC great again * Improve readability --------- Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2023-09-13 15:55:29 +03:00
Enum.random(long_random_urls),
Enum.random(["true", "false"]),
Enum.random(["true", "false"]),
to_string(Enum.random(1..9000))
]
]
|> Keyword.merge(geolocation)
|> then(&Plausible.Factory.build(:event, &1))
end)
end)
|> Plausible.TestUtils.populate_stats()
site =
site
|> Plausible.Site.start_import(
imported_stats_range.first,
imported_stats_range.last,
"Google Analytics"
)
|> Plausible.Repo.update!()
imported_stats_range
|> Enum.flat_map(fn date ->
Implement backend core for funnels (#3023) * Implement Funnel schema * Implement Funnels context module lib/plausible/funnels.ex - restored from: dca93621 Mark Vini's suggestion applied 7d1eec75 Update lib/plausible/funnels.ex 028036ad Review comments b694ccd5 Express the guard nicely acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels aea4ebc4 Access Funnel min/max steps via the __using__/1 macro 51f0397d Implement deleting funnels cf228630 wip 1f6fe25d Add number of steps to funnels list 89f10ecb wip 950a18d9 Dirty funnel save e62bfce5 Refactor funnel result evaluation 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 7a88fe44 Outline basic error handling c8ae3eaf Move Funnels to StatsController and use base query 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip fbd14e23 Absolute dirty wip 3ddd15ad wip 34ceb3f5 dirty wip test/plausible_web/controllers/api/stats_controller/funnels_test.exs - restored from: 9b532273 Test funnel stats controller Co-authored-by: Uku Taht <uku.taht@gmail.com> * Update Goals implementation lib/plausible/goal/schema.ex - restored from: 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion fbd14e23 Absolute dirty wip lib/plausible/goals.ex - restored from: aea4ebc4 Access Funnel min/max steps via the __using__/1 macro a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion ebdc4333 Extend the prompt in case of funnel-goal deletion 950a18d9 Dirty funnel save f06c3fcf wip test/plausible/goals_test.exs - restored from: a418c039 Implement funnel reduction logic on goal deletion 4a4ddbdc Optionally preload funnels for goals and stub funnel-goal deletion dee5bc9e Fixup tests * Update seeds * Split funnel schema modules * Add moduledoc to Funnel schema * Update Funnel.Step moduledoc * Add typespecs to Plausible.Funnels * Implement Phoenix.HTML.Safe for Funnel schema * Fixup a test after ordering goals by desc:id test/plausible_web/controllers/api/stats_controller/conversions_test.exs - restored from: 26a493cb Fixup a test after ordering goals by desc:id * Annotate Goal schema with type t() * Reword schema module docs * Fix up typespecs * Stop tagging Funnels.get/2 result * Nuke Goals.by_id!/2 * Test Funnels module test/plausible/funnels_test.exs - restored from: b7a6d3ad ya, rly 028036ad Review comments acd9c4f2 Prepare ephemeral funnel definitions so that users can test funnels 51f0397d Implement deleting funnels 1f6fe25d Add number of steps to funnels list dee5bc9e Fixup tests 950a18d9 Dirty funnel save 88e38a33 Update funnel tests bf47f654 Calculate conversion rate/dropoff in the backend 9e62ffb1 Make existing tests pass 2929bfd4 Minor rework b490403b !ifxup ae44db77 Add Funnels.list/1 function 4f3216b3 Unique steps 6e0c3efc Ensure step ordering works cea93ba1 It works I think c50ac0c2 WIP a466ec4c Dirty wip 34ceb3f5 dirty wip Co-authored-by: Uku Taht <uku.taht@gmail.com> * Apply changes related to 242081e5 * Evaluate funnels through `Stats.funnel/3` entry point --------- Co-authored-by: Uku Taht <uku.taht@gmail.com>
2023-06-13 15:01:39 +03:00
Enum.flat_map(0..Enum.random(1..500), fn _ ->
[
Plausible.Factory.build(:imported_visitors,
date: date,
pageviews: Enum.random(1..20),
visitors: Enum.random(1..20),
bounces: Enum.random(1..20),
visits: Enum.random(1..200),
visit_duration: Enum.random(1000..10000)
),
Plausible.Factory.build(:imported_sources,
date: date,
source: Enum.random(["", "Facebook", "Twitter", "DuckDuckGo", "Google"]),
visitors: Enum.random(1..20),
visits: Enum.random(1..200),
bounces: Enum.random(1..20),
visit_duration: Enum.random(1000..10000)
),
Plausible.Factory.build(:imported_pages,
date: date,
visitors: Enum.random(1..20),
pageviews: Enum.random(1..20),
exits: Enum.random(1..20),
time_on_page: Enum.random(1000..10000)
)
]
end)
end)
|> then(&Plausible.TestUtils.populate_stats(site, &1))
site
|> Plausible.Site.import_success()
|> Plausible.Repo.update!()