How to Add Logtivity to New Sites Using Code

One of the major benefits of Logtivity is that it can track all your WordPress sites from one dashboard. However, if you have many sites, it can be a slow process to configure all the Logtivity settings via the WordPress admin area.

It is possible to use code to activate Logtivity and manage the initial set-up. This code sample below can be added to your theme’s functions.php file, or to a plugin. Please make sure to replace the second line with your Team API key:

if (class_exists('Logtivity_Register_Site')) {
		'team_api_key' => 'ENTER_YOUR_TEAMS_API_KEY_HERE',
		'logtivity_disable_default_logging' => false,
		'logtivity_should_store_user_id' => true,
		'logtivity_should_store_ip' => true,
		'logtivity_should_log_profile_link' => true,
		'logtivity_should_log_username' => true,
		'logtivity_enable_debug_mode' => false,

How to use this code

There are four steps to using this code on your sites:

  1. Install the Logtivity plugin is installed on your sites. If you’re interested in speed, you can use WP-CLI or a site management tool that enables you to install the Logtivity plugin.
  2. Add this code to your sites using a plugin or your theme’s functions.php file.
  3. Run this code by visiting your site.
  4. Go to your dashboard and confirm that the site has been added correctly.

Please note that your Site API Key on’t work here. You will need the Team API Key. To get your Team API Key, click the “Team Settings” link inside the Logtivity app. Logtivity does also give you API keys for individual sites, but we do recommend using this Team API Key when following this guide.

How to use this code on multisite networks

This code will work on your multisite networks. Each site will be added as a unique site inside your Logtivity dashboard.

  • Make sure the Logtivity plugin is set to “Network Active”.
  • Place your code inside the main /wp-content/ folder for the multisite network.
  • If a site in your networks isn’t visited often, go to the frontend or admin area of that site. This will force the Logtivity code to run.