• Resolved Annonnimmo

    (@annonnimmo)


    Hi,
    first of all… thank you for your simple and effective plugin.

    Does Koko Analytics works well with WordPress Multisite, in particular with subdomains?

    It works either in “network activated” mode and in “single subsite activated” mode?

    It seems to me that activating Koko Analytics plugin only in one subsite, it does not create the “koko-analytics-collect.php” file in the root.
    Is it correct?

    Is there also some difference in performances, between the two mode?

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Lap

    (@lapzor)

    Koko should work in a multi-site setup, and no matter how the plugin is activated it should separate all data and settings per website.

    There is a slight performance difference if the koko-analytics-collect.php endpoint can’t be created. You can try to create the endpoint yourself manually or check the write permission on that folder as that is most often why Koko can’t create it.

    Hope that helps. If you have any questions, please let me know!

    Thread Starter Annonnimmo

    (@annonnimmo)

    Activating Koko Analytics plugin only in one subsite, I also noticed that “Exclude pageviews from these user roles” box is totally blank, showing no roles at all.

    Thread Starter Annonnimmo

    (@annonnimmo)

    All folders (including root) are writable, with permission 755.

    If I manually create koko-analytics-collect.php , what should I put inside it?

    If in future there will be some update of koko-analytics-collect.php contents, it will updates automatically?

    Also /wp-content/uploads/pageviews.php is not created.

    Thank you.

    • This reply was modified 2 years, 2 months ago by Annonnimmo.
    • This reply was modified 2 years, 2 months ago by Annonnimmo.
    Plugin Support Lap

    (@lapzor)

    Thread Starter Annonnimmo

    (@annonnimmo)

    Hi @lapzor,
    thank you.

    I think that you should always mention (especially for non-programmer users) that, the koko-analytics-collect.php code you provided, must be edited correcting the two path inside, to work… ??

    Anyway, with the actual code of Koko Analytics plugin, in the specific case of WordPress multisite, endpoint file method doesn’t work: in fact there is some specific code that disable it in “/src/class-endpoint-installer.php” from line 11

    ***************

    I’ve implemented some code to make it works, in various steps:

    1) manually create several endpoint files with the blog ID in the filename, e.g.
    koko-analytics-collect-2.php
    koko-analytics-collect-3.php

    2) in each endpoint files, correct the path of KOKO_ANALYTICS_BUFFER_FILE adjusting its corresponding site ID, e.g.
    __DIR__ . '/wp-content/uploads/sites/2/pageviews.php'
    __DIR__ . '/wp-content/uploads/sites/3/pageviews.php'

    3) in the functions.php insert this code snippet:
    define( 'KOKO_ANALYTICS_CUSTOM_ENDPOINT', '/koko-analytics-collect-'. get_current_blog_id() .'.php' );

    In this way, it works fine!
    At least for “single subsite activated” plugin mode; I didn’t try with “network activated” plugin mode.

    Plugin Support Lap

    (@lapzor)

    Thank you for your feedback! I will ask Danny to look into possible improvements for automatically installing the endpoint for Koko on a multisite setup.

    Homepage and category pages are indeed not counted as Koko works by counting hits on the post or page ID. So anything that doesn’t have an ID (like a category or latest posts page) currently can’t be counted.

    Hello everybody.

    Even this issue is already resolved, I’d like to add my workaround, for reuse and also feedback.

    Within a mu-plugin I have:

    // Will be used by site_url(), so make this relative.
    const CUSTOM_ENDPOINT = '/content/koko-collect.php';
    
    ...
    
    if ( file_exists( MY_SITE_ROOT_DIR . CUSTOM_ENDPOINT ) ) {
    
    	$cbid = get_current_blog_id();
    	define( 'KOKO_ANALYTICS_CUSTOM_ENDPOINT', CUSTOM_ENDPOINT . '?c=' . $cbid );
    	define( 'KOKO_ANALYTICS_BUFFER_FILE', WP_CONTENT_DIR . '/uploads/sites/' . $cbid . '/pageviews.php' );
    }

    And inside my koko-collect.php, the important lines are:

    // WordPress site_ID of the current blog
    $site_id = (int) $_GET['c'];
    
    // path to pageviews.php file in uploads directory
    define( 'KOKO_ANALYTICS_BUFFER_FILE', __DIR__ . "/uploads/sites/$site_id/pageviews.php" );

    As you can see from the code, all sites of the network use the exact same scheme to save uploads to a folder corresponding their blog_id, which is done by a filter on upload_dir.

    My filter looks a little different, but this is the essence:

    add_filter('upload_dir', function ( array $upload_dir ) : array {
    
    	$upload_dir['basedir'] = WP_CONTENT_DIR . '/uploads/sites/' . get_current_blog_id();
    
    	return $upload_dir;
    });

    Maybe this helps someone. Have a nice day, everybody.

    Plugin Support Lap

    (@lapzor)

    Thanks for sharing!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WP Multisite (with domains)’ is closed to new replies.