Support » Plugin: Google Analytics Post Pageviews » here's a legit question about hitting API limits

  • here’s a legit question;

    to avoid hitting the API limit on sites with lot of visits and with cache such as memcached etc. won’t it be cool instead of having the plugin to request data when every user visits the site, doing a wp_schedule_event() where you every hour request visits for all the pages? Then you save the results in post meta or some other cache….

    function get_visits_cron() {
    	if ( !wp_next_scheduled( "get_visits" ) ) {
    		wp_schedule_event(time(), "hourly", "get_visits");
    	}
    }
    
    add_action("wp", "get_visits_cron");

    and you have a function where you get all visits for all pages from google;

    function get_visits_hourly() {
    
    	global $wpdb;
    
    	// Loop Through All Posts
    	$args = array( "posts_per_page" => "-1" );
    	$the_query = new WP_Query( $args );
    
    	while ( $the_query->have_posts() ) : $the_query->the_post();
    
    	// here goes the script to get the visits
    
    	// updating the post meta
    	update_post_meta(get_the_ID(), "_page_views", $Result);
    
    	endwhile;
    	wp_reset_postdata();
    
    }
    
    add_action("get_visits", "get_visits_hourly");

    those are examples and mine is only a question, I didn’t gave a check at plugins code.. so

    thanks

    https://wordpress.org/plugins/google-analytics-post-pageviews/

Viewing 1 replies (of 1 total)
  • Plugin Author maximevalette

    (@maximevalette)

    With this solution you would hit the API rate limiting very fast because it’s capped for a small number of requests per second.

Viewing 1 replies (of 1 total)
  • The topic ‘here's a legit question about hitting API limits’ is closed to new replies.