INN / Google-Analytics-Popular-Posts

A WordPress plugin that uses Google Analytics data to determine the most popular posts on your site and display a list of popular posts via the included widget.
https://wordpress.org/plugins/ga-popular-posts/
23 stars 7 forks source link

wp_query to make loop to return results to custom template #75

Closed newvision2112 closed 6 years ago

newvision2112 commented 6 years ago

Hello,

Your plugin looks useful. However I've run into a couple issues.

  1. I have a custom coded theme so can't use the widget. Can you share basic PHP code for a WP_query to test pulling back data from the database tables? Then I can test writing a list of popular posts to my templates.

  2. When installed and updated, it looks like the database tables are empty(?). I've verified that I'm pulling in data and connected to my GA account. If I can create a query then I can test this.

Thanks, Dean

benlk commented 6 years ago

Hi Dean,

We strongly recommend registering a sidebar in your custom theme, outputting the sidebar on the page, and then putting the widget in your sidebar. Failing that, you can use the WordPress template tag function the_widget to output the widget, but we've never attempted that with this plugin and cannot guarantee whether it will work. Sample code for querying the data can be found in the widget included in this plugin, at https://github.com/INN/Google-Analytics-Popular-Posts/blob/master/classes/AnalyticsPopularWidget.php#L44-L165

If the database tables are indeed empty, and are not updating, please see if you can reproduce the issue described in https://github.com/INN/Google-Analytics-Popular-Posts/issues/72

newvision2112 commented 6 years ago

Hi Ben,

Got it working! Thank you.

Q: Can I change the timeframe to 30 days? So most popular posts based on Google Analytics for last 30 days?

Best, Dean

On Wed, Mar 28, 2018 at 1:23 PM, Dean Pajevic dean.pajevic@gmail.com wrote:

Hi Ben,

Thank you for the detailed suggestions. I will test now.

Appreciate it, Dean

On Wed, Mar 28, 2018 at 12:53 PM, Ben Keith notifications@github.com wrote:

Hi Dean,

We strongly recommend registering a sidebar https://codex.wordpress.org/Sidebars in your custom theme, outputting the sidebar on the page, and then putting the widget in your sidebar. Failing that, you can use the WordPress template tag function the_widget https://developer.wordpress.org/reference/functions/the_widget/ to output the widget, but we've never attempted that with this plugin and cannot guarantee whether it will work. Sample code for querying the data can be found in the widget included in this plugin, at https://github.com/INN/Google-Analytics-Popular-Posts/blob/m aster/classes/AnalyticsPopularWidget.php#L44-L165

If the database tables are indeed empty, and are not updating, please see if you can reproduce the issue described in #72 https://github.com/INN/Google-Analytics-Popular-Posts/issues/72

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/INN/Google-Analytics-Popular-Posts/issues/75#issuecomment-376996804, or mute the thread https://github.com/notifications/unsubscribe-auth/ADqErJ0sAjWt1wOws82Soksob7N6tOjxks5ti9w9gaJpZM4S_Iea .

benlk commented 6 years ago

Not easily. You'd need to completely rewrite AnalyticBridgePopularPosts::query() to grab posts from more than the last two days https://github.com/INN/Google-Analytics-Popular-Posts/blob/7378ac73f924b438c0ab6c0f04cd521a23725117/classes/AnalyticBridgePopularPosts.php#L35-L148

And you'd see a massive performance hit on your site when running that query.

newvision2112 commented 6 years ago

Hi Ben,

Thanks for explaining the weighted part and the need to re-write the query.

It would be useful to just ask Google for top posts for last 30 days and have them do the heavy lifting which they already do and return a list. I'll see what I can do around that.

Dean

On Wed, Mar 28, 2018 at 5:29 PM, Ben Keith notifications@github.com wrote:

Not easily. You'd need to completely rewrite AnalyticBridgePopularPosts:: query() to grab posts from more than the last two days https://github.com/INN/Google-Analytics-Popular-Posts/blob/ d3a5ffccec1902fe158e7f69ba4f708f49e15fdd/classes/ AnalyticBridgePopularPosts.php#L52-L65

And you'd see a massive performance hit on your site when running that query.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/INN/Google-Analytics-Popular-Posts/issues/75#issuecomment-377071560, or mute the thread https://github.com/notifications/unsubscribe-auth/ADqErPbi7c-Gf4m8RLJ68kNNFjyYVDRnks5tjBzpgaJpZM4S_Iea .