Plausible Analytics and better Link Unfurling!

modified:   make_post_sell/models/shop.py
	new file:   make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py
	modified:   make_post_sell/templates/base.j2
	modified:   make_post_sell/templates/content.j2
	modified:   make_post_sell/templates/product.j2
	modified:   make_post_sell/templates/shop_settings.j2
	renamed:    make_post_sell/templates/snippets/google-analytics.j2 -> make_post_sell/templates/snippets/analytics.j2
	modified:   make_post_sell/views/shop.py
This commit is contained in:
Russell Ballestrini 2022-01-08 12:00:03 -05:00
parent c211df66a8
commit 03680800a8
8 changed files with 111 additions and 27 deletions

View file

@ -52,6 +52,7 @@ class Shop(RBase, Base):
# example: "UA-XX31XX60-3".
google_analytics_id = Column(Unicode(32), nullable=True, default="")
plausible_domain_name = Column(Unicode(256), nullable=True, default="")
# example: "cus_12345678AbCdEF" but may be null.
# this is how the shop pays for make_post_sell.

View file

@ -0,0 +1,24 @@
"""plausible_domain_name column on shop
Revision ID: cdad5c220c39
Revises: bfc4195a7f56
Create Date: 2022-01-07 19:57:52.202252
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cdad5c220c39'
down_revision = 'bfc4195a7f56'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('mps_shop', sa.Column('plausible_domain_name', sa.Unicode(length=256), nullable=True, server_default=""))
def downgrade():
op.drop_column('mps_shop', 'plausible_domain_name')

View file

@ -7,31 +7,28 @@
{%- endif %}
<html lang="en">
<head>
<title>{% block title %}{{ request.app_domain }}{% endblock %}</title>
<meta charset="utf-8" />
{% set theme_color = request.shop.ribbon_color_1 or "#5871ad" %}
<!-- this makes mobile pretty... -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="{{ theme_color }}">
<!--
TODO: merge all these CSS files into a single file during builds.
In prod we use the single concatenated ("streamlined") all.css file.
In dev we use each CSS file busted out like so:
In prod single concatenated ("streamlined") all.css file.
In dev each CSS file busted out like so:
-->
<link rel="stylesheet" href="/static/css/common.css">
<link rel="stylesheet" href="/static/css/mps.css">
<link rel="stylesheet" href="/static/css/alerts.css">
<link rel="stylesheet" href="/static/css/lib.css">
{% include 'snippets/google-analytics.j2' %}
{% include 'snippets/analytics.j2' %}
{% set theme_color = request.shop.ribbon_color_1 or "#5871ad" %}
<!-- this makes mobile pretty... -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="{{ theme_color }}">
<meta charset="utf-8">
{%- block append_to_head_tag_section %}
{% endblock append_to_head_tag_section %}
<title>{{ request.app_domain }}</title>
{% endblock %}
</head>
<body>

View file

@ -1,5 +1,22 @@
{% extends "base.j2" -%}
{%- block append_to_head_tag_section %}
<link rel="canonical" href="{{ product.absolute_url(request) }}" />
<title>{{ product.title }}</title>
<meta property="og:title" content="{{ product.title }}" />
<meta name="description" content="{{ product.description }}">
<meta property="og:description" content="{{ product.description }}" />
<meta property="og:type" content="article" />
{%- if "thumbnail1" in product.extensions %}
<meta property="og:image" content="{{ request.app["bucket.secure_uploads.get_endpoint"] }}/{{ product.s3_path }}/thumbnail1?ts={{ product.updated_timestamp }}" />
{%- endif %}
<!--
<meta name="keywords" content="HTML, CSS, meta, data, metadata, link, unfurling, link unfurling">
<meta name="author" content="Captain Susan">
-->
{%- endblock append_to_head_tag_section -%}
{%- block call_to_action -%}
{% if request.user.can_edit_shop(request.shop) %}
<a href="/p/{{ product.id }}/edit" class="product-edit-button mps-button mps-button-small">&#9998; Edit</a>

View file

@ -1,5 +1,22 @@
{% extends "base.j2" -%}
{%- block append_to_head_tag_section %}
<link rel="canonical" href="{{ product.absolute_url(request) }}" />
<title>{{ product.title }}</title>
<meta property="og:title" content="{{ product.title }}" />
<meta name="description" content="{{ product.description }}">
<meta property="og:description" content="{{ product.description }}" />
<meta property="og:type" content="article" />
{%- if "thumbnail1" in product.extensions %}
<meta property="og:image" content="{{ request.app["bucket.secure_uploads.get_endpoint"] }}/{{ product.s3_path }}/thumbnail1?ts={{ product.updated_timestamp }}" />
{%- endif %}
<!--
<meta name="keywords" content="HTML, CSS, meta, data, metadata, link, unfurling, link unfurling">
<meta name="author" content="Captain Susan">
-->
{%- endblock append_to_head_tag_section -%}
{%- block call_to_action -%}
{% if request.user.can_edit_shop(request.shop) %}
<a href="/p/{{ product.id }}/edit" class="product-edit-button mps-button mps-button-small">&#9998; Edit</a>

View file

@ -71,19 +71,6 @@
<br />
<br />
<label for="google_analytics_id_input">Google Analytics Tracking Id</label>
<input
name = "google_analytics_id"
type = "text"
id = "google_analytics_id"
class = "mps-google-analytics-id"
value = "{% if google_analytics_id %}{{ google_analytics_id }}{% endif %}"
placeholder = "Google Analytics Id"
/>
<br />
<br />
<label for="stripe_public_api_key_input">Stripe Public API Key</label>
<input
name = "stripe_public_api_key"
@ -110,6 +97,36 @@
<br />
<br />
<!--
<br />
<br />
<label for="google_analytics_id_input">Google Analytics Tracking Id (optional)</label>
<input
name = "google_analytics_id"
type = "text"
id = "google_analytics_id"
class = "mps-shop-name"
value = "{% if google_analytics_id %}{{ google_analytics_id }}{% endif %}"
placeholder = "Google Analytics Id"
/>
-->
<label for="plausible_domain_name_input">Plausible Analytics Domain Name (optional)</label>
<input
name = "plausible_domain_name"
type = "text"
id = "plausible_domain_name"
class = "mps-shop-name"
value = "{% if plausible_domain_name %}{{ plausible_domain_name }}{% endif %}"
placeholder = "ex: plausible.io"
/>
<br />
<br />
<input type="submit" name="submit" class="mps-submit" value="Save Settings" />
<br />

View file

@ -1,3 +1,7 @@
{% if request.shop and request.shop.domain_name and request.shop.plausible_domain_name %}
<script defer data-domain="{{ request.shop.domain_name }}" src="https://{{ request.shop.plausible_domain_name }}/js/plausible.js"></script>
{% endif %}
{% if request.shop and request.shop.google_analytics_id %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ request.shop.google_analytics_id }}"></script>

View file

@ -303,6 +303,7 @@ def shop_settings(request):
ribbon_color_2 = request.params.get("ribbon_color_2", shop.ribbon_color_2)
google_analytics_id = request.params.get("google_analytics_id", shop.google_analytics_id)
plausible_domain_name = request.params.get("plausible_domain_name", shop.plausible_domain_name)
stripe_public_api_key = request.params.get("stripe_public_api_key", shop.stripe_public_api_key)
stripe_secret_api_key = request.params.get("stripe_secret_api_key", shop.stripe_secret_api_key)
@ -374,6 +375,11 @@ def shop_settings(request):
msg = ("You set the shop's Google Analytics Id.", "success")
request.session.flash(msg)
if plausible_domain_name != shop.plausible_domain_name:
shop.plausible_domain_name = plausible_domain_name
msg = ("You set the shop's Plausible Analytics Domain Name.", "success")
request.session.flash(msg)
if stripe_public_api_key and stripe_public_api_key != shop.stripe_public_api_key:
if stripe_public_api_key.startswith("pk_"):
shop.stripe_public_api_key = stripe_public_api_key
@ -487,6 +493,7 @@ def shop_settings(request):
"ribbon_color_1": ribbon_color_1,
"ribbon_color_2": ribbon_color_2,
"google_analytics_id": google_analytics_id,
"plausble_domain_name": plausible_domain_name,
"stripe_public_api_key": stripe_public_api_key,
"stripe_secret_api_key": stripe_secret_api_key,
"signed_posts": signed_posts,