PHP SDK
Complete example
<?php
/**
* Plugin Name: Acme Gallery
*/
use Plugie\Insights\Insights;
require __DIR__ . '/vendor/autoload.php';
define('ACME_GALLERY_VERSION', '4.2.1');
$acme_insights = Insights::init([
'plugin_id' => 'acme-gallery',
'plugin_version' => ACME_GALLERY_VERSION,
'plugin_file' => __FILE__,
'consent_version' => '1',
'site_url' => home_url(),
]);
add_action('init', static function () use ($acme_insights): void {
$acme_insights->feature('gallery_block')
->flag('enabled', true)
->gauge('instances', static fn(): int => (int) get_option('acme_gallery_count', 0));
$acme_insights->feature('lightbox')
->flag('enabled', (bool) get_option('acme_lightbox', false))
->value('theme', (string) get_option('acme_lightbox_theme', 'dark'));
});
add_action('acme_gallery_created', static function () use ($acme_insights): void {
$acme_insights->feature('gallery_block')->added('instances');
});
// Settings page: an unticked checkbox, and the preview beside it.
add_action('acme_settings_saved', static function (array $settings) use ($acme_insights): void {
if (!empty($settings['share_usage'])) {
$acme_insights->consent()->grant('1');
} else {
$acme_insights->revokeConsent(!empty($settings['tell_plugie_i_stopped']));
}
});