Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Chuck Mac

    (@chuckmac)

    Thanks for trying out the plugin.

    There is no “easy” way built in to display the statistics on the front end such as a shortcode. That said, the code should be reusable to build an extension off of it that would display the data on the frontend.

    Specifically the display_dashboard_widget function in includes/class-analytics-for-cloudflare-admin-dashboard.php.

    Thread Starter Luke

    (@danceyrselfclean_admin)

    Thanks for the reply, I’ll look into it.

    Would there be any way to do this for multiple domains, for example I have about 20 domains all on the same cloudflare account and would love to display the analytics for each account based on the URL or a custom field URL I could input for each user on WordPress.

    Plugin Author Chuck Mac

    (@chuckmac)

    I had never really thought about that use case when developing this (which is great!).

    I will add some filter in and push a new release in a day or 2 so that the domain can be changed programmatically.

    Thread Starter Luke

    (@danceyrselfclean_admin)

    That would be awesome, thanks for considering this. I look forward to an update.

    Plugin Author Chuck Mac

    (@chuckmac)

    I pushed a new version (1.0.2) which has some new filters for the API settings. Specifically the domain is cmd_analytics_for_cloudflare_set_api_domain. The trick here is that this is the ZoneID key for the domain… not just the bare domain name.

    I also played around for a few minutes trying to get the chart to display on the front end. I was able to get it working with the following code in a template.

    //Need to include the dashboard widget class since that is typically only loaded on is_admin
    $plugin_file = WP_PLUGIN_DIR . '/analytics-for-cloudflare/includes/class-analytics-for-cloudflare-admin-dashboard.php';
    require_once( $plugin_file );
    
    //Create a new instance of the class
    $dashboard = new CMD_Analytics_For_Cloudflare_Admin_Dashboard();
    //Enqueue the chartJS styles / javascript.  Trick it into thinking we are on the dashboard index.php page
    $dashboard->enqueue_dashboard_scripts_styles('index.php');
    //Load up the chart!
    $dashboard->display_dashboard_widget();

    Good luck!

    Thread Starter Luke

    (@danceyrselfclean_admin)

    That’s brilliant thanks for that. I’ve updated and using your code it can show the stats on the front end. I’m having a little issue with the filter however.

    Do you know where I could I find the ZoneID for each domain? I found the following but could not locate it in Cloudflare:
    “Each zone (yourdomain.com) on CloudFlare has a unique number identifier. If you need to locate the zoneid for a domain, simply go to the “Reports and Stats’ link for that domain (the zone id appears at the end with an equal sign, such as zid=xxxxxx).”

    PHP is not my strong point but would something like the following work once I know the zoneid:

    add_filter( 'cmd_analytics_for_cloudflare_set_api_domain', 'set_cloudflare_user_domain' );
    function set_cloudflare_user_domain() {
      return 'ZONEID';
    }

    ZONEID obviously replaced with an actual zoneid for a specific domain.

    Plugin Author Chuck Mac

    (@chuckmac)

    Your code looks like it should work.

    The direction for how to determine the zoneID on CloudFlare look like they are outdated. I poked around for a few minutes and can’t see an easy way to extract them from there.

    If you have it linked up in your WordPress dashboard you can do a view source on the settings page… the cmd_analytics_for_cloudflare_settings[domain] dropdown box has all the zoneIDs in it.

    ex:

    <select name="cmd_analytics_for_cloudflare_settings[domain]" data-dynamite-selected="true">
    		<option value="thisismyzoneid" selected="selected">domain.com</option>
    </select>
    Thread Starter Luke

    (@danceyrselfclean_admin)

    That’s perfect, thanks for all your help you’ve been amazing.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Anyway to display analytics on a post or page’ is closed to new replies.