Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:20:41+00:00 2026-06-09T11:20:41+00:00

I am going to extend the analytics plugin.I want to get most popular pages.

  • 0

I am going to extend the analytics plugin.I want to get most popular pages. I read the google api docs. The great thing is that there is already a php library to get data from google analytics api ( Great!) and also there is a good plugin in the pyro core files.
I mean the Plugin_Integration.

Now what I want is to add new method to this plugin. also this is not good idea to edit the core files. so, there are two ways:

1- re implement the plugins as a shared plugin (duplicating the code which is already there)
2- extending the core plugin.

but unfortunately I don’t know how I can extend the core plugin. 🙁

the pluing is like this in the core:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Integration Plugin
 *
 * Attaches a Google Analytics tracking piece of code.
 *
 * @author      PyroCMS Dev Team
 * @package     PyroCMS\Core\Plugins
 */
class Plugin_Integration extends Plugin
{

    /**
     * Partial
     *
     * Loads Google Analytic
     *
     * Usage:
     *   {{ integration:analytics }}
     *
     * @return string The analytics partial view.
     */
    function analytics()
    {
        return $this->load->view('fragments/google_analytics', NULL, TRUE);
    }

    /**
     * Visitors
     *
     * Uses Google Analytics data to show page views 
     * and visitors for a given time period
     *
     * Usage:
     *   {{ integration:visitors }}
     *
     * @return array The number of page views and visitors.
     */
    public function visitors()
    {
        $data       = array('visits' => 0, 'views' => 0);
        $start      = $this->attribute('start', '2010-01-01');
        $end        = $this->attribute('end', date('Y-m-d'));
        $refresh    = $this->attribute('refresh', 24); // refresh the cache every n hours

        if (Settings::get('ga_email') and Settings::get('ga_password') and Settings::get('ga_profile'))
        {
            // do we have it? Return it
            if ($cached_response = $this->pyrocache->get('analytics_plugin'))
            {
                return $cached_response;
            }

            else
            {
                try
                {
                    $this->load->library('analytics', array(
                        'username' => Settings::get('ga_email'),
                        'password' => Settings::get('ga_password')
                    ));

                    // Set by GA Profile ID if provided, else try and use the current domain
                    $this->analytics->setProfileById('ga:'.Settings::get('ga_profile'));

                    $this->analytics->setDateRange($start, $end);

                    $visits = $this->analytics->getVisitors();
                    $views  = $this->analytics->getPageviews();

                    if ($visits)
                    {
                        foreach ($visits as $visit)
                        {
                            if ($visit > 0) $data['visits'] += $visit;
                        }
                    }

                    if ($views)
                    {
                        foreach ($views as $view) 
                        {
                            if ($view > 0) $data['views'] += $view;
                        }
                    }

                    // Call the model or library with the method provided and the same arguments
                    $this->pyrocache->write($data, 'analytics_plugin', 60 * 60 * (int) $refresh); // 24 hours
                }

                catch (Exception $e)
                {
                    log_message('error', 'Could not connect to Google Analytics. Called from the analytics plugin');
                }
            }

            return $data;
        }
    }
}

i need to add the method like this but in a separate plugin which extends above plugin

public function most_viewed()
{//the logic}

anyone can give a piece advise ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:20:44+00:00Added an answer on June 9, 2026 at 11:20 am

    PyroCMS has no functionality for extending anything in the core, and of course duplicating the code is not the best idea. So here’s what I would do: Create your own library, but extend the previous one.

    So you include the old library’s file before your class definition and then do


    class My_lib extends The_lib

    Not perfect, but I guess the best option.

    PS: if you feel confident about your extension of the lib, why not submit it to the PyroCMS repository?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extend an API (the Visio API - Microsoft.Office.Interop.Visio). The classes are
My DAO's are going to extend the HibernateDaoSupport class that spring provides. Now I
I have a website and going to extend it, so users will upload their
I want to extend the mappings database of DBpedia. Therefore I want to run
I have a business application which I am going to extend by creating mobile
I am going to develop a complex web application related to affiliates. I want
I'm going to extend the existing std::map class and add a new function to
Quick novice question: I want to extend a class as an array, like so
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
going thru a tutorial on python lists,I tried to write a python function which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.