|
| 1 | +defmodule PlausibleWeb.Live.InstallationV2 do |
| 2 | + @moduledoc """ |
| 3 | + User assistance module around Plausible installation instructions/onboarding |
| 4 | + """ |
| 5 | + use PlausibleWeb, :live_view |
| 6 | + |
| 7 | + def mount( |
| 8 | + %{"domain" => domain}, |
| 9 | + _session, |
| 10 | + socket |
| 11 | + ) do |
| 12 | + site = |
| 13 | + Plausible.Sites.get_for_user!(socket.assigns.current_user, domain, [ |
| 14 | + :owner, |
| 15 | + :admin, |
| 16 | + :editor, |
| 17 | + :super_admin, |
| 18 | + :viewer |
| 19 | + ]) |
| 20 | + |
| 21 | + {:ok, |
| 22 | + assign(socket, |
| 23 | + site: site, |
| 24 | + installation_form: to_form(site.installation_meta.script_config), |
| 25 | + flow: "provisioning", |
| 26 | + installation_type: "manual" |
| 27 | + )} |
| 28 | + end |
| 29 | + |
| 30 | + def render(assigns) do |
| 31 | + ~H""" |
| 32 | + <div> |
| 33 | + <PlausibleWeb.Components.FlowProgress.render flow={@flow} current_step="Install Plausible" /> |
| 34 | +
|
| 35 | + <.focus_box> |
| 36 | + <:title> |
| 37 | + Manual installation |
| 38 | + </:title> |
| 39 | +
|
| 40 | + <:subtitle :if={@installation_type == "manual"}> |
| 41 | + Paste this snippet into the <code><head></code> |
| 42 | + section of your site. See our |
| 43 | + <.styled_link href="https://plausible.io/docs/integration-guides" new_tab={true}> |
| 44 | + installation guides. |
| 45 | + </.styled_link> |
| 46 | + Once done, click the button below to verify your installation. |
| 47 | + </:subtitle> |
| 48 | +
|
| 49 | + <div :if={@installation_type in ["manual", "GTM"]}> |
| 50 | + <.snippet_form |
| 51 | + installation_form={@installation_form} |
| 52 | + installation_type={@installation_type} |
| 53 | + flow={@flow} |
| 54 | + site={@site} |
| 55 | + /> |
| 56 | + </div> |
| 57 | + </.focus_box> |
| 58 | + </div> |
| 59 | + """ |
| 60 | + end |
| 61 | + |
| 62 | + defp snippet_form(assigns) do |
| 63 | + ~H""" |
| 64 | + <form id="snippet-form"> |
| 65 | + <div class="relative"> |
| 66 | + <textarea |
| 67 | + id="snippet" |
| 68 | + class="w-full border-1 border-gray-300 rounded-md p-4 text-sm text-gray-700 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300" |
| 69 | + rows="5" |
| 70 | + readonly |
| 71 | + ><%= render_snippet(@installation_type, @site) %></textarea> |
| 72 | +
|
| 73 | + <a |
| 74 | + onclick="var input = document.getElementById('snippet'); input.focus(); input.select(); document.execCommand('copy'); event.stopPropagation();" |
| 75 | + href="javascript:void(0)" |
| 76 | + class="absolute flex items-center text-xs font-medium text-indigo-600 no-underline hover:underline bottom-2 right-4 p-2 bg-white dark:bg-gray-900" |
| 77 | + > |
| 78 | + <Heroicons.document_duplicate class="pr-1 text-indigo-600 dark:text-indigo-500 w-5 h-5" /> |
| 79 | + <span> |
| 80 | + COPY |
| 81 | + </span> |
| 82 | + </a> |
| 83 | + </div> |
| 84 | +
|
| 85 | + <.h2 class="mt-8 text-sm font-medium">Optional measurements</.h2> |
| 86 | + <.script_config_control |
| 87 | + field={@installation_form["outbound-links"]} |
| 88 | + label="Outbound links" |
| 89 | + tooltip="Automatically track clicks on external links. These count towards your billable pageviews." |
| 90 | + learn_more="https://plausible.io/docs/outbound-link-click-tracking" |
| 91 | + /> |
| 92 | + <.script_config_control |
| 93 | + field={@installation_form["file-downloads"]} |
| 94 | + label="File downloads" |
| 95 | + tooltip="Automatically track file downloads. These count towards your billable pageviews." |
| 96 | + learn_more="https://plausible.io/docs/file-downloads-tracking" |
| 97 | + /> |
| 98 | + <.script_config_control |
| 99 | + field={@installation_form["form-submissions"]} |
| 100 | + label="Form submissions" |
| 101 | + tooltip="Automatically track form submissions. These count towards your billable pageviews." |
| 102 | + learn_more="https://plausible.io/docs/form-submissions-tracking" |
| 103 | + /> |
| 104 | +
|
| 105 | + <.disclosure> |
| 106 | + <.disclosure_button class="mt-8 flex items-center group"> |
| 107 | + <.h2 class="text-sm font-medium">Advanced options</.h2> |
| 108 | + <Heroicons.chevron_down mini class="size-4 ml-1 mt-0.5 group-data-[open=true]:rotate-180" /> |
| 109 | + </.disclosure_button> |
| 110 | + <.disclosure_panel> |
| 111 | + <ul class="list-disc list-inside mt-2 space-y-2"> |
| 112 | + <.advanced_option |
| 113 | + config={@site.installation_meta.script_config} |
| 114 | + variant="tagged-events" |
| 115 | + label="Manual tagging" |
| 116 | + tooltip="Tag site elements like buttons, links and forms to track user activity. These count towards your billable pageviews. Additional action required." |
| 117 | + learn_more="https://plausible.io/docs/custom-event-goals" |
| 118 | + /> |
| 119 | + <.advanced_option |
| 120 | + config={@site.installation_meta.script_config} |
| 121 | + variant="404" |
| 122 | + label="404 error pages" |
| 123 | + tooltip="Find 404 error pages on your site. These count towards your billable pageviews. Additional action required." |
| 124 | + learn_more="https://plausible.io/docs/error-pages-tracking-404" |
| 125 | + /> |
| 126 | + <.advanced_option |
| 127 | + config={@site.installation_meta.script_config} |
| 128 | + variant="hash" |
| 129 | + label="Hashed page paths" |
| 130 | + tooltip="Automatically track page paths that use a # in the URL." |
| 131 | + learn_more="https://plausible.io/docs/hash-based-routing" |
| 132 | + /> |
| 133 | + <.advanced_option |
| 134 | + config={@site.installation_meta.script_config} |
| 135 | + variant="pageview-props" |
| 136 | + label="Custom properties" |
| 137 | + tooltip="Attach custom properties (also known as custom dimensions) to pageviews or custom events to create custom metrics. Additional action required." |
| 138 | + learn_more="https://plausible.io/docs/custom-props/introduction" |
| 139 | + /> |
| 140 | + <.advanced_option |
| 141 | + config={@site.installation_meta.script_config} |
| 142 | + variant="revenue" |
| 143 | + label="Ecommerce revenue" |
| 144 | + tooltip="Assign monetary values to purchases and track revenue attribution. Additional action required." |
| 145 | + learn_more="https://plausible.io/docs/ecommerce-revenue-tracking" |
| 146 | + /> |
| 147 | + </ul> |
| 148 | + </.disclosure_panel> |
| 149 | + </.disclosure> |
| 150 | +
|
| 151 | + <.button_link |
| 152 | + :if={not is_nil(@installation_type)} |
| 153 | + href={"/#{URI.encode_www_form(@site.domain)}/verification"} |
| 154 | + type="submit" |
| 155 | + class="w-full mt-8" |
| 156 | + > |
| 157 | + <%= if @flow == PlausibleWeb.Flows.domain_change() do %> |
| 158 | + I understand, I'll update my website |
| 159 | + <% else %> |
| 160 | + <%= if @flow == PlausibleWeb.Flows.review() do %> |
| 161 | + Verify your installation |
| 162 | + <% else %> |
| 163 | + Start collecting data |
| 164 | + <% end %> |
| 165 | + <% end %> |
| 166 | + </.button_link> |
| 167 | + </form> |
| 168 | + """ |
| 169 | + end |
| 170 | + |
| 171 | + defp script_config_control(assigns) do |
| 172 | + ~H""" |
| 173 | + <div class="mt-2 p-1 text-sm"> |
| 174 | + <div class="flex items-center"> |
| 175 | + <.input mt?={false} field={@field} label={@label} type="checkbox" /> |
| 176 | + <div class="ml-2 collapse md:visible"> |
| 177 | + <.tooltip sticky?={false}> |
| 178 | + <:tooltip_content> |
| 179 | + {@tooltip} |
| 180 | + <br /><br />Click to learn more. |
| 181 | + </:tooltip_content> |
| 182 | + <a href={@learn_more} target="_blank" rel="noopener noreferrer"> |
| 183 | + <Heroicons.information_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" /> |
| 184 | + </a> |
| 185 | + </.tooltip> |
| 186 | + </div> |
| 187 | + <div class="ml-2 visible md:invisible"> |
| 188 | + <a href={@learn_more} target="_blank" rel="noopener noreferrer"> |
| 189 | + <Heroicons.information_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" /> |
| 190 | + </a> |
| 191 | + </div> |
| 192 | + </div> |
| 193 | + </div> |
| 194 | + """ |
| 195 | + end |
| 196 | + |
| 197 | + defp advanced_option(assigns) do |
| 198 | + ~H""" |
| 199 | + <li class="p-1 text-sm"> |
| 200 | + <div class="inline-flex items-center"> |
| 201 | + <div>{@label}</div> |
| 202 | + <div class="ml-2 collapse md:visible"> |
| 203 | + <.tooltip sticky?={false}> |
| 204 | + <:tooltip_content> |
| 205 | + {@tooltip} |
| 206 | + <br /><br />Click to learn more. |
| 207 | + </:tooltip_content> |
| 208 | + <a href={@learn_more} target="_blank" rel="noopener noreferrer"> |
| 209 | + <Heroicons.information_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" /> |
| 210 | + </a> |
| 211 | + </.tooltip> |
| 212 | + </div> |
| 213 | + <div class="ml-2 visible md:invisible"> |
| 214 | + <a href={@learn_more} target="_blank" rel="noopener noreferrer"> |
| 215 | + <Heroicons.information_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" /> |
| 216 | + </a> |
| 217 | + </div> |
| 218 | + </div> |
| 219 | + </li> |
| 220 | + """ |
| 221 | + end |
| 222 | + |
| 223 | + defp render_snippet("manual", site) do |
| 224 | + """ |
| 225 | + <script defer src="#{tracker_url(site)}"></script> |
| 226 | + <script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script> |
| 227 | + """ |
| 228 | + end |
| 229 | + |
| 230 | + defp tracker_url(site) do |
| 231 | + "https://plausible.io/js/script-#{site.domain}.js" |
| 232 | + end |
| 233 | +end |
0 commit comments