Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic PWA support #2405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## Unreleased

### Added
- Add basic Progressive Web App support
- The ability to escape `|` characters with `\` in Stats API filter values
- An upper bound of 1000 to the `limit` parameter in Stats API
- The `exclusions` script extension now also takes a `data-include` attribute tag
Expand Down
4 changes: 4 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ if (embedButton) {
}
})
}

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register( 'serviceWorker.js' );
}
41 changes: 41 additions & 0 deletions assets/static/app.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"dir": "ltr",
"lang": "en",
"short_name": "Plausible",
"name": "Plausible Analytics",
"icons": [
{
"src": "/images/icon/plausible_logo.svg",
"type": "image/svg+xml",
"sizes": "any"
},
{
"src": "/images/icon/plausible_logo_192px.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/images/icon/plausible_logo_192px_maskable.png",
"type": "image/png",
"sizes": "192x192",
"purpose": "maskable"
},
{
"src": "/images/icon/plausible_logo_512px.png",
"type": "image/png",
"sizes": "512x512"
},
{
"src": "/images/icon/plausible_logo_512px_maskable.png",
"type": "image/png",
"sizes": "512x512",
"purpose": "maskable"
}
],
"start_url": "/",
"background_color": "#252f3f",
"display": "standalone",
"orientation": "portrait",
"theme_color": "#5850ec",
"description": "Web analytics tools"
}
1 change: 1 addition & 0 deletions assets/static/images/icon/plausible_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/static/serviceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
self.addEventListener( 'install', ( event ) => {
console.log( 'Service worker installed' );
} );

self.addEventListener( 'activate', ( event ) => {
console.log( 'Service worker activated' );
} );

self.addEventListener( 'fetch', ( event ) => {
console.log( 'Service worker fetch' );
} );
2 changes: 1 addition & 1 deletion lib/plausible_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule PlausibleWeb.Endpoint do
at: "/",
from: :plausible,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
only: ~w(css fonts images js favicon.ico robots.txt app.webmanifest serviceWorker.js)

plug Plug.Static,
at: "/kaffy",
Expand Down
1 change: 1 addition & 0 deletions lib/plausible_web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="apple-touch-icon" href="/images/icon/apple-touch-icon.png">
<title><%= assigns[:title] || "Plausible · Simple, privacy-friendly alternative to Google Analytics" %></title>
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
<link rel="manifest" href="/app.webmanifest">
<%= render("_tracking.html", assigns) %>
<script type="text/javascript" data-pref="<%= @conn.assigns[:theme] || (@conn.assigns[:current_user] && @conn.assigns[:current_user].theme) %>" src="<%= Routes.static_path(@conn, "/js/applyTheme.js") %>"></script>
</head>
Expand Down