### install.trial.started
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs when a free trial is started on an existing product install.
```APIDOC
## install.trial.started
### Description
This event is triggered when a free trial is initiated for an existing product installation.
### Event
install.trial.started
```
--------------------------------
### Project Structure After Installation
Source: https://freemius.com/help/documentation/saas-sdk/react-starter/installation
This illustrates the directory structure of the installed React Starter Kit components within your project.
```text
react-starter/
├─ components/
├─ hooks/
├─ icons/
└─ utils/
```
--------------------------------
### Install SDK with Bun
Source: https://freemius.com/help/documentation/saas-sdk/js-sdk/installation
Install the Freemius SDK, checkout module, and zod for schema validation using Bun.
```bash
bun add @freemius/sdk @freemius/checkout zod
```
--------------------------------
### Programmatic Checkout Link Examples
Source: https://freemius.com/help/documentation/checkout/integration/hosted-checkout
Examples demonstrating how to construct hosted checkout URLs for different scenarios, including pre-selecting license counts and currencies.
```text
https://checkout.freemius.com/product/1234/plan/5678/
```
```text
https://checkout.freemius.com/product/1234/plan/5678/licenses/10/
```
```text
https://checkout.freemius.com/product/1234/plan/5678/currency/eur/
```
```text
https://checkout.freemius.com/product/1234/plan/5678/licenses/10/currency/eur/
```
--------------------------------
### Freemius Product readme.txt Example
Source: https://freemius.com/help/documentation/release-management/deployment
This is an example of a readme.txt file for a Freemius product, demonstrating how to use comments to conditionally include content for free and premium users.
```plaintext
=== My Awesome Product ===
Requires at least: 3.0
Tested up to: 4.9
Stable tag: 3.1.0
License: GPLv2 or later
== Description ==
This is the best product ever!
== Installation ==
1. Upload the product to your blog.
2. Activate it.
[//]: # fs_premium_only_begin
3. Enter the license key you received after the purchase and activate it.
[//]: # fs_premium_only_end
== Change Log ==
[//]: # fs_premium_only_begin
= 1.0.0 =
* New: New premium feature!
[//]: # fs_premium_only_end
[//]: # fs_free_only_begin
= 1.0.0 =
* New: New free feature!
[//]: # fs_free_only_end
```
--------------------------------
### Install SDK with npm
Source: https://freemius.com/help/documentation/saas-sdk/js-sdk/installation
Install the Freemius SDK, checkout module, and zod for schema validation using npm.
```bash
npm install @freemius/sdk @freemius/checkout zod
```
--------------------------------
### Install SDK with Yarn
Source: https://freemius.com/help/documentation/saas-sdk/js-sdk/installation
Install the Freemius SDK, checkout module, and zod for schema validation using Yarn.
```bash
yarn add @freemius/sdk @freemius/checkout zod
```
--------------------------------
### Complete Overlay Checkout Example with License Options
Source: https://freemius.com/help/documentation/checkout/integration/overlay-checkout
A full example demonstrating the overlay checkout integration, including product details, license selection, and success callback handling. This code is suitable for plans with multiple pricing tiers.
```html
```
--------------------------------
### Install SDK with pnpm
Source: https://freemius.com/help/documentation/saas-sdk/js-sdk/installation
Install the Freemius SDK, checkout module, and zod for schema validation using pnpm.
```bash
pnpm add @freemius/sdk @freemius/checkout zod
```
--------------------------------
### Annual Discount Example for 3 Licenses
Source: https://freemius.com/help/llms-full.txt
Illustrates the calculation of the annual discount for three licenses, using the same monthly and annual prices as the single license example.
```text
3 | (10 × 12 − 100) × 3 | $60
```
--------------------------------
### Deploy Programmatically with Freemius API (PHP Example)
Source: https://freemius.com/help/documentation/release-management/deployment
This PHP example demonstrates how to deploy a product version programmatically using the Freemius REST API. Ensure you have the necessary SDK or implement the API calls directly.
```php
deployProduct("your_product_id", "path/to/your/archive.zip");
echo "Deployment script executed (example).";
?>
```
--------------------------------
### Example Product-Specific License Recovery URL
Source: https://freemius.com/help/documentation/wordpress/license-recovery-tool
An example of a product-specific license recovery URL, demonstrating the use of actual product ID and slug.
```text
https://dashboard.freemius.com/license-recovery/11707/my-awesome-plugin/
```
--------------------------------
### install.installed
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs whenever a product is being installed (triggered before `install.activated`).
```APIDOC
## install.installed
### Description
This event is triggered when a product is installed, prior to activation.
### Event
install.installed
```
--------------------------------
### Bundle Discount Calculation with maximize
Source: https://freemius.com/help/llms-full.txt
Example calculation of bundle discount when `bundle_discount` is set to `maximize`.
```text
Child sum = (10 + 20) × 12 = $360
Bundle price = $260
Bundle discount = $360 − $260 = $100
```
--------------------------------
### Bundle Discount Calculation with true
Source: https://freemius.com/help/llms-full.txt
Example calculation of bundle discount when `bundle_discount` is set to `true`.
```text
Child sum (annual) = 100 + 200 = $300
Bundle price = $260
Bundle discount = $300 − $260 = $40
```
--------------------------------
### Install React Starter Kit Components with Bun
Source: https://freemius.com/help/documentation/saas-sdk/react-starter/installation
Use this command to add all necessary React Starter Kit components and dependencies to your project when using Bun.
```bash
bun x shadcn@latest add https://shadcn.freemius.com/all.json
```
--------------------------------
### URL-encode License Key in JavaScript
Source: https://freemius.com/help/documentation/saas/integrating-license-key-activation
Example of how to URL-encode the license key when constructing a GET request URL in JavaScript.
```javascript
const url = `https://api.freemius.com...?license_key=${encodeURIComponent(licenseKey)}`;
```
--------------------------------
### Install React Starter Kit Components with npm
Source: https://freemius.com/help/documentation/saas-sdk/react-starter/installation
Use this command to add all necessary React Starter Kit components and dependencies to your project when using npm.
```bash
npx shadcn@latest add https://shadcn.freemius.com/all.json
```
--------------------------------
### URL-encode License Key in PHP
Source: https://freemius.com/help/documentation/saas/integrating-license-key-activation
Example of how to URL-encode the license key when constructing a GET request URL in PHP.
```php
$url = "https://api.freemius.com...?license_key=" . url_encode($license_key);
```
--------------------------------
### Multi-Plans Pricing Table HTML
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/usage
HTML structure for a pricing table with multiple plans, a license selector, and 'Get Started' buttons.
```html
Simple Pricing
Choose the plan that works best for you
Starter
from
$8.99
per month
Basic features
Email support
Community access
Pro
from
$12.99
per month
Advanced features
Priority support
API access
Business
from
$30.00
per month
All features
24/7 support
Dedicated account
```
--------------------------------
### Install React Starter Kit Components with pnpm
Source: https://freemius.com/help/documentation/saas-sdk/react-starter/installation
Use this command to add all necessary React Starter Kit components and dependencies to your project when using pnpm.
```bash
pnpm dlx shadcn@latest add https://shadcn.freemius.com/all.json
```
--------------------------------
### Retrieve an Active License by ID API Endpoint
Source: https://freemius.com/help/documentation/saas/integrating-license-key-activation
Use this GET request to fetch the activated license details. Replace placeholders with your specific product, install, and license information.
```http
GET /v1/products/{product_id}/installs/{install_id}/license.json?uid={uuid}&license_key={license_key}
Host: api.freemius.com
```
--------------------------------
### Install React Starter Kit Components with Yarn
Source: https://freemius.com/help/documentation/saas-sdk/react-starter/installation
Use this command to add all necessary React Starter Kit components and dependencies to your project when using Yarn.
```bash
yarn dlx shadcn@latest add https://shadcn.freemius.com/all.json
```
--------------------------------
### Create Custom Checkout Buttons
Source: https://freemius.com/help/llms-full.txt
Create custom checkout buttons using the useCheckout hook after wrapping your application with CheckoutProvider. This example shows buttons for starting a trial and making a purchase.
```javascript
export default function PurchasePage() {
const checkout = useCheckout();
return (
-
);
}
```
--------------------------------
### Download Invoice (Partial Example)
Source: https://freemius.com/help/documentation/ai/sticklight
This is a partial Deno serverless function intended for downloading invoices. It includes the initial setup for authentication via Supabase but the core invoice retrieval logic is not shown.
```typescript
Deno.serve(async (req: Request) => {
if (req.method === 'OPTIONS')
return new Response(null, { headers: corsHeaders });
try {
const authHeader = req.headers.get('Authorization');
if (!authHeader) throw new Error('Not authenticated');
const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_ANON_KEY')!,
{ global: { headers: { Authorization: authHeader } } }
);
const {
data: { user },
error: authError,
} = await supabase.auth.getUser();
if (authError || !user) throw new Error('Not authenticated');
const url = new URL(req.url);
```
--------------------------------
### Get Trial Upgrade URL
Source: https://freemius.com/help/llms-full.txt
Use this method to generate a URL that directs users to the product's in-dashboard pricing page for starting a trial. Replace `my_fs()` with your actual Freemius instance name.
```php
// Make sure to change my_fs() to your Freemius instance name.
my_fs()->get_trial_url();
```
--------------------------------
### User Entitlement Functions for Next.js
Source: https://freemius.com/help/documentation/saas-sdk/framework/nextjs
Provides functions to process purchase information, retrieve user entitlements, and get Freemius user data. It requires setup with a database client like Prisma and user authentication.
```typescript
import { PurchaseInfo, UserRetriever } from '@freemius/sdk';
import { freemius } from './freemius';
import { prisma } from '@/lib/prisma';
import { UserFsEntitlement, User } from '@generated/prisma';
import { auth } from '@/lib/auth';
/**
* Process the purchase info and update the local database.
*
* This function is called when a purchase happens with Freemius.
*/
export async function processPurchaseInfo(
fsPurchase: PurchaseInfo
): Promise {
const user = await getUserByEmail(fsPurchase.email);
if (!user) {
// User not found, cannot process the purchase. Alternately you can create a new user here.
return;
}
await prisma.userFsEntitlement.upsert({
where: {
fsLicenseId: fsPurchase.licenseId,
},
update: fsPurchase.toEntitlementRecord(),
create: fsPurchase.toEntitlementRecord({ userId: user.id }),
});
}
/**
* Get the user's entitlement.
*
* @returns The user's active entitlement or null if the user does not have an active entitlement.
*/
export async function getUserEntitlement(
userId: string
): Promise {
const entitlements = await prisma.userFsEntitlement.findMany({
where: { userId, type: 'subscription' },
});
return freemius.entitlement.getActive(entitlements);
}
/**
* Get the Freemius user for the current session.
*
* This is used by the Freemius SDK to identify the user.
*
* @returns The Freemius user or null if the user is not logged in.
*/
export const getFsUser: UserRetriever = async () => {
const session = await auth.api.getSession({
headers: await headers(),
});
const entitlement = session
? await getUserEntitlement(session.user.id)
: null;
const email = session?.user.email ?? undefined;
return freemius.entitlement.getFsUser(entitlement, email);
};
```
--------------------------------
### Updating Install Properties
Source: https://freemius.com/help/documentation/saas/app-integration
This endpoint allows you to update various properties of an Install entity in Freemius, which helps in synchronizing your application's state and improving analytics. It requires the install ID and a Bearer token for authentication.
```APIDOC
## PUT /v1/installs/{install_id}.json
### Description
Updates the properties of an existing Install entity associated with a Freemius license. This is used to keep application analytics and state synchronized with Freemius.
### Method
PUT
### Endpoint
`/v1/installs/{install_id}.json`
### Headers
- **Host**: `api.freemius.com`
- **Content-Type**: `application/json`
- **Authorization**: `Bearer {install_api_token}`
### Parameters
#### Path Parameters
- **install_id** (string) - Required - The unique identifier for the install entity.
#### Request Body
- **version** (string) - Optional - The current version of your application.
- **title** (string) - Optional - A descriptive identifier for the activation (e.g., `user-foo@example.com - Windows 10`).
- **country_code** (string) - Optional - A two-letter ISO 3166-1 alpha-2 country code.
- **language** (string) - Optional - The language code for the application's usage (e.g., `en-GB`).
- **platform_version** (string) - Optional - The version of the platform the application is running on.
- **sdk_version** (string) - Optional - The version of the SDK used by the application.
- **programming_language_version** (string) - Optional - The version of the programming language the application depends on.
- **is_beta** (boolean) - Optional - Indicates if the user is using a beta version.
### Request Example
{
"version": "1.2.3",
"title": "user-foo@example.com - Windows 10",
"country_code": "US",
"language": "en-US",
"platform_version": "134.0.6998",
"sdk_version": "2.1.0",
"programming_language_version": "18.16.0"
}
### Response
#### Success Response (200)
(No specific response schema provided in source, but typically indicates success)
#### Response Example
(No example provided in source)
```
--------------------------------
### Example Menu Configuration
Source: https://freemius.com/help/llms-full.txt
Illustrates how to configure the 'menu' array for custom plugin settings pages in the WordPress admin.
```php
'slug' => 'my-plugin-menu'
```
```php
'parent' => array('slug' => 'options-general.php')
```
```php
'first-path' => 'admin.php?page=my-plugin-menu'
```
```php
'contact' => true
```
```php
'support' => true
```
```php
'addons' => true
```
```php
'affiliation' => false
```
```php
'account' => true
```
--------------------------------
### install.updated
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs whenever an installation data is updated (in addition to specific install update events).
```APIDOC
## install.updated
### Description
This event is triggered whenever general installation data is updated, in addition to more specific update events.
### Event
install.updated
```
--------------------------------
### Initialize Freemius SDK
Source: https://freemius.com/help/documentation/wordpress-sdk/integrating-freemius-sdk
Paste this snippet into the top of your main plugin's PHP file or your theme's functions.php file. It initializes the Freemius SDK with product-specific information.
```php
'1234',
'slug' => 'my-awesome-plugin',
'type' => 'plugin',
'public_key' => 'pk_xxxxxxx',
'name' => 'My Awesome Plugin',
'developer_id' => '5678'
)
);
// Link to WordPress plugin or theme.
$freemius->add_plugin_support( 'my-awesome-plugin', array(
'slug' => 'my-awesome-plugin',
'type' => 'plugin'
) );
```
--------------------------------
### install.premium.activated
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs whenever the paid product version is activated.
```APIDOC
## install.premium.activated
### Description
This event is triggered when the premium or paid version of a product is activated for an installation.
### Event
install.premium.activated
```
--------------------------------
### Initialize Freemius SDK and Load Product Versions
Source: https://freemius.com/help/documentation/wordpress-sdk/gists
This snippet shows how to initialize the Freemius SDK and conditionally load either the free or premium version of a plugin based on the license status. It uses global variables and requires the Freemius SDK to be included.
```php
is_premium() ) {
require_once dirname(__FILE__) . 'path/to/free/loader.php';
}
if ( my_fs()->is__premium only() ) {
if ( my_fs()->can_use_premium_code() ) {
require_once dirname(__FILE__) . 'path/to/premium/loader.php';
}
}
```
--------------------------------
### install.activated
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs whenever a user is opted-in, and after reactivation of a product.
```APIDOC
## install.activated
### Description
This event is triggered when a user opts into a product or when a product installation is reactivated.
### Event
install.activated
```
--------------------------------
### Initialize and Open Freemius Overlay Checkout
Source: https://freemius.com/help/documentation/checkout/integration/freemius-checkout-buy-button
Use this snippet to initialize the FS.Checkout constructor with product and plan details, then open the checkout with specific options like license count and a success callback.
```javascript
const checkout = new FS.Checkout({
product_id: '',
plan_id: '',
// ... Other options
});
checkout.open({
licenses: 10,
// ... Other options and callbacks
success: function (purchaseData) {
console.log('Purchase completed!', purchaseData);
},
});
```
--------------------------------
### Initialize Checkout SDK via CDN
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/usage
Include the SDK script from the CDN and initialize the Checkout instance with your product ID.
```html
```
--------------------------------
### Example Hosted Checkout URL
Source: https://freemius.com/help/llms-full.txt
This is an example URL for a Freemius Hosted Checkout page. It includes parameters for product ID, plan ID, billing cycle, and other display options.
```URL
https://checkout.freemius.com/product/16423/plan/27409/?hide_licenses=true&billing_cycle=monthly&title=My%20Software&show_reviews=true&show_refund_badge=true&s_ctx_ts=1736411534&sandbox=ffb191fd7ac2dd20bf29a717ffc13d06&cancel_url=https%3A%2F%2Ffreemius.com%2Fcheckout%2F
```
--------------------------------
### Install Checkout JS SDK using Bun
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/installation
Install the official Freemius Checkout JS SDK package using Bun. This is required for bundling with tools like Vite or Webpack.
```bash
bun add @freemius/checkout
```
--------------------------------
### Initialize Checkout with Sandbox Object
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/usage
Demonstrates how to create a Checkout instance using a sandbox object for testing in a development environment. Ensure the sandbox object is fetched securely.
```javascript
import { Checkout } from '@freemius/checkout';
const sandbox = await fetchSandboxObjectSomehow();
const checkout = new Checkout({
product_id: '0001',
sandbox, // <-- pass the sandbox object here
});
```
--------------------------------
### Install Checkout JS SDK using pnpm
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/installation
Install the official Freemius Checkout JS SDK package using pnpm. This is required for bundling with tools like Vite or Webpack.
```bash
pnpm add @freemius/checkout
```
--------------------------------
### Install Checkout JS SDK using Yarn
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/installation
Install the official Freemius Checkout JS SDK package using Yarn. This is required for bundling with tools like Vite or Webpack.
```bash
yarn add @freemius/checkout
```
--------------------------------
### install.connected
Source: https://freemius.com/help/documentation/saas/events-webhooks
Occurs whenever a user opts in for sharing basic device/website info after previously opting out from it.
```APIDOC
## install.connected
### Description
This event is triggered when a user opts in to share device or website information after previously opting out.
### Event
install.connected
```
--------------------------------
### Install Checkout JS SDK using npm
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/installation
Install the official Freemius Checkout JS SDK package using npm. This is required for bundling with tools like Vite or Webpack.
```bash
npm i @freemius/checkout
```
--------------------------------
### Freemius Webhook Integration Example
Source: https://freemius.com/help/documentation/saas/app-integration
Example Node.js code for setting up a webhook endpoint to receive and process events from Freemius. It includes signature verification and handling for license and payment events.
```APIDOC
## Webhook Endpoint
### Description
This Node.js example demonstrates how to set up a webhook endpoint to receive and verify events from Freemius. It handles license creation, plan changes, and payment notifications.
### Language
JavaScript (Node.js)
### Code
```javascript
import crypto from 'crypto';
import express from 'express';
import bodyParser from 'body-parser';
const app = express();
const PRODUCT_SECRET_KEY = '';
app.post('/webhook', bodyParser.raw({ type: '*/*' }), (req, res) => {
const input = req.body.toString('utf8');
const hash = crypto
.createHmac('sha256', PRODUCT_SECRET_KEY)
.update(input)
.digest('hex');
const signature = (req.headers['x-signature'] as string) || '';
// Verify the signature and authenticity of the webhook event.
const isValid = crypto.timingSafeEqual(Buffer.from(hash, 'hex'), Buffer.from(signature, 'hex'));
if (!isValid) {
res.status(200).send();
return;
}
const fsEvent = JSON.parse(input);
processEvent(fsEvent);
res.status(200).send();
});
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});
function processEvent(fsEvent) {
let appInstances;
switch (fsEvent.type) {
case 'license.created':
appInstances = myApp().findByExternalUser(fsEvent.objects.user);
myApp().pushService(appInstances).sendActivationNotice( fsEvent.objects.license );
break;
case 'license.plan.changed':
case 'license.extended':
case 'license.shortened':
case 'license.expired':
case 'license.deleted':
case 'license.cancelled':
appInstances = myApp().findByExternalLicenseId(fsEvent.objects.license.id);
myApp().pushService(appInstances).sendSyncSignal();
break;
case 'payment.created':
appInstances = myApp().findByExternalLicenseId(fsEvent.data.license_id);
myApp().pushService(appInstances).sendPaymentNotice(fsEvent.objects.payment);
break;
}
}
```
```
--------------------------------
### Initialize Checkout SDK via NPM
Source: https://freemius.com/help/documentation/saas-sdk/checkout-js-sdk/usage
Import the Checkout class from the @freemius/checkout package and initialize it with your product ID.
```javascript
import { Checkout } from '@freemius/checkout';
const checkout = new Checkout({
product_id: '1234',
});
```
--------------------------------
### Update Install Properties via API
Source: https://freemius.com/help/documentation/saas/app-integration
Make a PUT request to the Freemius API to update install properties. Use the install_api_token as the Bearer authentication token. Recommended to update once a day or on significant events.
```http
PUT /v1/installs/{install_id}.json
Host: api.freemius.com
Content-Type: application/json
Authorization: Bearer {install_api_token}
{
"version": "1.2.3",
"title": "user-foo@example.com - Windows 10",
"country_code": "US",
"language": "en-US",
"platform_version": "134.0.6998",
"sdk_version": "2.1.0",
"programming_language_version": "18.16.0"
}
```