Google Analytics post views in WordPress?

Does anyone know of a wordpress plugin or widget that uses Google Analytics to display the page views to the user of the page they are on?

The reason it need to integrate with google analytics is that I have page views from existing posts that I wish to be counted and the normal page view plugins don’t show the historical views.

Related posts

Leave a Reply

2 comments

  1. Please check out the WordPress Post Analytics Plugin that we (WisdmLabs) have created.

    http://wordpress.org/extend/plugins/wordpress-post-analytics/
    This is available on the WordPress plugin repository as a free download.

    We link your Google Analytics account to the plugin and pull data from the Analytics backend to showcase stats right inside any post. You have a choice of using shortcode or a template code snippet to embed the plugin on your website.

    Feel free to let us know your feedback on the support forum or through our website.

  2. You could do something like the following (merely an example, do not take literally):

    $posts = get_posts( 'posts_per_page=-1' );
    foreach ( $posts as $post ) {
        $url = url_encode( get_permalink( $post->ID ) );
        $get = wp_remote_get( "https://www.google.com/analytics/api?visits_for_url=$url" );
        if ( $data = wp_remote_retrieve_body( $get ) )
             update_post_meta( $post->ID, 'analytics_view_count', $data );
    }
    

    This process would then run as a daily/half-daily WP cron event.

    I have zero experience with the API, so how you query data by URL, or as to what data types are returned, you’d need to read up on the documentation.

    I would also assume that it has a query limit – you might need to throttle the process, or at least break it up into batches (perhaps the latter, especially if you have a large number of posts).