Ghost/ghost
Simon Backx a7b583050c
Added link tracking to paywall (#15414)
closes https://github.com/TryGhost/Team/issues/1908

### Problem:
- We need tracking on the paywall links in each email. (we cannot ignore them because those buttons are probably gonna have a higher paid conversion attribution than others).
- Currently we only add the paywall HTML to an email when processing each batch. So if we batch an email to 1.000 recipients per 100, we'll generate the paywall HTML 10 times. 
- We cannot replace links in `renderEmailForSegment` because that methods will get called multiple times. We don't want to have multiple redirect instances created for the same link in the same email.

###  Solution:
- Move the generation of the paywall to the `serialize` method of the post email serializer.
- Surround the generated paywall with HTML-comments so we can remove it if required in `renderEmailForSegment` depending on the member segment we are sending the email to.

---

### Before:

**Serialize output:**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
            <!--members-only-->
                <p>Content visible for paid members only</p>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```

To be modified later by  `renderEmailForSegment`:

**Paid members (nothing changed):**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
            <!--members-only-->
                <p>Content visible for paid members only</p>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```

**Free members (paywall _added_):**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
                <h2>Generated paywall here</h2>
                <a href="https://subscribe.com">Subscribe to read the full post</a>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```

### After this change:

**Serialize output:**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
            <!--members-only-->
                <p>Content visible for paid members only</p>
             <!-- PAYWALL -->
                <h2>Generated paywall here</h2>
                <a href="https://subscribe.com/?tracked">Subscribe to read the full post</a>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```

To be modified later by  `renderEmailForSegment`:

**Paid members (paywall removed):**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
            <!--members-only-->
                <p>Content visible for paid members only</p>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```

**Free members (members-only content removed):**
```html
<html>
    <body>
        <h1>Generated email header</h1>
        <p>Generated text</p>

        <div>
            <!-- POST CONTENT START -->
                <h1>Post title</h1>
                <p>Content visible for all members</p>
            <!-- PAYWALL -->
                <h2>Generated paywall here</h2>
                <a href="https://subscribe.com/?tracked">Subscribe to read the full post</a>
            <!-- POST CONTENT END -->
        </div>
    </body>
</html>
```
2022-09-16 10:08:12 +02:00
..
adapter-manager Increased adapter manager test coverage 2022-09-06 17:51:57 +08:00
admin Updated Explore section category link 2022-09-16 07:35:52 +02:00
api-framework Fixed some type issues with the api framework 2022-08-23 14:49:29 +01:00
api-version-compatibility-service Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
bootstrap-socket Added logging configuration option for timestamps to use the local timezone 2022-08-31 10:29:55 +01:00
constants Added one week in seconds value to constants 2022-09-15 10:56:34 +08:00
core Added link tracking to paywall (#15414) 2022-09-16 10:08:12 +02:00
custom-theme-settings-service Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
domain-events Organized package dependencies 2022-08-18 11:55:49 +02:00
email-analytics-provider-mailgun Organized package dependencies 2022-08-18 11:55:49 +02:00
email-analytics-service Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
email-content-generator Organized package dependencies 2022-08-18 11:55:49 +02:00
express-dynamic-redirects Organized package dependencies 2022-08-18 11:55:49 +02:00
extract-api-key Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
html-to-plaintext Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
job-manager Update dependency date-fns to v2.29.3 2022-09-13 18:24:39 +01:00
link-redirects Pin dependencies 2022-09-14 18:53:15 +01:00
link-replacement Added email_track_clicks setting (#15409) 2022-09-15 15:48:22 +02:00
link-tracking Added initial link-tracking package 2022-09-14 13:24:17 -04:00
magic-link Update dependency @types/nodemailer to v6.4.6 2022-09-13 08:39:26 +01:00
mailgun-client Added logging configuration option for timestamps to use the local timezone 2022-08-31 10:29:55 +01:00
member-analytics-service Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
member-attribution Wired up member attribution from email clicks (#15407) 2022-09-14 15:50:54 -04:00
member-events Updated subscription created/canceled events data 2022-09-10 11:06:34 +05:30
members-analytics-ingress Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
members-api Wired up member attribution from email clicks (#15407) 2022-09-14 15:50:54 -04:00
members-csv Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
members-events-service Moved attribution event handler to events service (#15379) 2022-09-07 16:41:59 +02:00
members-importer 🐛 Fixed empty error csv file for member imports (#15274) 2022-08-24 00:49:30 +05:30
members-ssr Added missing return in create-stripe-update-session 2022-08-29 14:02:58 +02:00
minifier Update dependency terser to v5.15.0 2022-08-23 19:47:07 +00:00
mw-api-version-mismatch Organized package dependencies 2022-08-18 11:55:49 +02:00
mw-cache-control Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
mw-error-handler Removed bluebird catch predicates from API endpoints 2022-08-24 11:27:09 +01:00
mw-session-from-token Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
mw-update-user-last-seen Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
mw-vhost Cleaned up unused test utils 2022-08-18 11:55:49 +02:00
oembed-service Update metascraper to v5.30.4 2022-09-02 19:09:45 +00:00
offers Wired events for triggering email alerts for subscription creation/cancellation 2022-09-10 11:06:34 +05:30
package-json Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
payments Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
security Updated @tryghost dependencies (#15349) 2022-09-08 18:32:13 +01:00
session-service Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
settings-path-manager Update dependency date-fns to v2.29.3 2022-09-13 18:24:39 +01:00
staff-service Updated staff service to trigger alerts via events 2022-09-10 11:06:34 +05:30
stripe Moved member email alert trigger to member creation 2022-09-10 11:06:34 +05:30
update-check-service Update dependency uuid to v9 2022-09-07 13:06:48 +01:00
verification-trigger Improved verification email copy 2022-08-29 12:18:46 +08:00
version-notifications-data-service Organized package dependencies 2022-08-18 11:55:49 +02:00