deptagency / dept-engineering-blog-ui

dept-engineering-blog-ui.vercel.app
MIT License
1 stars 3 forks source link

Enable "Unsubscribe" functionality #99

Open nring opened 12 months ago

nring commented 12 months ago

The template we forked our code from implemented a custom Newsletter Subscription button. This hooked into Ghost's membership functionality to opt-in users to newsletters of new blog posts. Ghost's membership functionality is a suite of tools to manage subscriptions and user settings. This poses a number of issues given our current set up.

  1. We're using the hosted version of the Ghost Admin, where we're able to create and edit individual posts. We could host the platform ourselves but that brings with it added overhead and administration. Because we're using the hosted version, a public-facing version of the site is automatically generated with the default Ghost template. We have opted to make this version of the site private (essentially turn it off) so we don't have duplicate content.

  2. The problem with this implementation is that we lose the ability to access membership functionality. This includes newsletter subscriptions as well as a host of other features we're not using at the moment.

  3. We also lose the ability to change what the linked domains are in our auto-generated email newsletters. We have redirects set up to make sure linked content is available on our custom domain (see section on "Other things to keep in mind"). However, the "unsubscribe" link functionality does not work. Currently, it directs to: https://dept-engineering-blog.ghost.io/unsubscribe/?uuid=member-uuid&newsletter=newsletter-uuid. When the user clicks this, they end up instead at https://engineering.deptagency.com/?action=unsubscribe&newsletter=34bb27ba-af93-4374-8e93-aa48e1baddfe&uuid=cf4ec616-4724-446d-86e6-46d3f11628d8. Using this source code helpfully provided by an admin on the Ghost forums, we should be able to programmatically unsubscribe a user from our specific newsletter with the Ghost Admin API. (Note, that we would be able to change this domain if we self-hosted the Ghost platform.)

Other things to keep in mind

  1. Redirects. We have 301 redirects set up in the "Labs" section of the ghost admin. This does affect how the unsubscribe URL is currently redirected from our Ghost site to our custom domain:
    301:
    ^\/$: https://engineering.deptagency.com
    ^\/(?!assets|ghost|unsubscribe|contact)([a-zA-Z0-9-]+)\/$: https://engineering.deptagency.com/$1
    ^\/contact$: https://deptagency.com/contact
    /why-i-built-a-new-state-management-library-2/: /why-i-built-a-new-state-management-library/
nring commented 12 months ago

After extracting that source code into our own app, calling the /members/member/newsletters resource directly doesn't work because our site is in private mode. Requests to https://{our-ghost-domain}/members/member/newsletters are redirected to https://{our-ghost-domain}/private/?r={original-url}.

If we want to go down this route, we'll have to both turn off private mode and use a custom theme that doesn't output any views so we don't have duplicate content indexed by SEO robots. I was able to get a similar response from Ghost support:

The most common solution for headless setups would be to use a custom theme which doesn't output any post data on the ghost.io site: thus it cannot be reached or indexed (but should still allow the Ghost generated links for unsubscribes to work as expected).

For example, there is a community generated theme here for this use case specifically.