Imagine we have a set of premium pages: /premium/content, /premium/articles, etc. Suppose we want to allow users a couple free views every month to sample the content, but after that, we want to show a paywall to encourage users to upgrade to a premium account. Note that different people may be interested in different content, so we do not want to simply pick which articles are free to access, but rather limit the amount of content that is consumed by free users.
In this tutorial, we'll create a policy so that Gatekeeper will return a "deny" authorization when a non-paying user accesses too many premium articles within a month. You can configure your webserver to show a page to sell a subscription when that happens.
We'll start by creating a page group for our premium content. Go to the page groups page and click the "New page group" button. We'll set up our new page group to match all pages that start with "/premium/".
Note the ".+" at the end of the page. This is a regular expressions that means "one or more of any character", and allows our single page definition to match /premium/content, /premium/articles/my-neat-article, and so on.
For now, we'll apply this policy to everyone, so we'll use the system default group known as any. Later on, you'll want add a separate policy to allow subscribers unlimited access.
Next, we'll add a policy to limit the number of free samples. Go to the policies page and click the "New policy" button. Our policy will allow users 3 free visits to premium content pages every 30 days. On the 4th visit, it will deny access.
That's it. You now have a set of pages that can be sampled a limited number of times before further action is required. Of course, you'll also want to make sure you have a separate policy that allows your subscribers unlimited access. Since that policy should take precendence over this one, it should have a priority number that is more positive than the priority number of this policy. For more details, consult this tutorial on whitelisting users. Additionally, you can also configure Gatekeeper to return a custom response other than "deny".