Skip to content

Commit

Permalink
add iframe plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Jul 2, 2024
1 parent 44eb0fb commit 9414b9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/controllers/admin/iframe_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Admin
class IframeController < Decidim::Admin::ApplicationController
def index
enforce_permission_to :read, :admin_dashboard
end
end
end
3 changes: 3 additions & 0 deletions app/views/admin/iframe/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<iframe plausible-embed src="<%= ENV["PLAUSIBLE_IFRAME"] %>" scrolling="no" frameborder="0" loading="lazy" style="width: 1px; min-width: 100%; height: 1600px;"></iframe>
<div style="font-size: 14px; padding-bottom: 14px;">Stats powered by <a target="_blank" style="color: #4F46E5; text-decoration: underline;" href="https://plausible.io">Plausible Analytics</a></div>
<script async src="https://<%= ENV["PLAUSIBLE_HOST"] %>/js/embed.host.js"></script>
3 changes: 3 additions & 0 deletions app/views/layouts/decidim/_head_extra.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% if ENV["PLAUSIBLE_HOST"].present? %>
<script defer data-domain="coopmmunity.eu" src="https://<%= ENV.fetch("PLAUSIBLE_HOST") %>/js/script.js"></script>
<% end %>
10 changes: 10 additions & 0 deletions config/initializers/custom_admin_iframe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

Decidim.menu :admin_menu do |menu|
menu.add_item :custom_iframe,
"Estadístiques web",
Rails.application.routes.url_helpers.admin_iframe_index_path,
icon_name: "bar-chart-2-line",
position: 10,
if: ENV.fetch("PLAUSIBLE_IFRAME", nil).present?
end
9 changes: 7 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# frozen_string_literal: true

require "sidekiq/web"
require "sidekiq/cron/web"

Rails.application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?

mount Decidim::Core::Engine => "/"
authenticate :user, ->(u) { u.admin? } do
mount Sidekiq::Web => "/sidekiq"
end
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

namespace :admin do
resources :iframe, only: [:index]
end

mount Decidim::Core::Engine => "/"
end

0 comments on commit 9414b9c

Please sign in to comment.