Jump to content

Search the Community

Showing results for tags 'viewtracker'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 1 result

  1. Hi. I made a little module a while ago to track pageviews. It stores each pageview record as a PW page (hidden, under a hidden parent page "ViewTracker"), with the user & page IDs and timestamp. <?php /** * Processwire ProcessViewtracker Module * * ProcessWire 2.5.3 * Copyright (C) 2014 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * http://processwire.com * */ /* TO-DO: - add settings: templates select, clear/archive option..? - add auto-creation of templates/fields on install */ class ProcessViewtracker extends WireData implements Module { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * * @return array * */ public static function getModuleInfo() { return array( 'title' => 'ViewTracker', 'version' => 1, 'summary' => 'Records pageviews.', 'href' => '', 'singular' => true, 'autoload' => true, 'icon' => 'eye', ); } public function init() { // add a hook after each page is rendered $this->addHookAfter('Page::render', $this, 'viewTracker'); } /** * ViewTracker hooks into every page after it's rendered and records the views for specified template(s) * (and adds "Hello World" text at the bottom) * */ public function viewTracker($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; // add to selected templates if($page->template == 'vessel') { // create record $r = new Page(); $r->template = 'pageview'; $r->parent = wire('pages')->get('/viewtracker/'); $r->user = $this->user; $r->vessel_id = $page; $r->name = $this->user . $page . date('YmdHisu'); $r->status = $r->status | Page::statusHidden; $r->save(); // record if segment if($this->input->urlSegment(1) !== '') { //$segment = "$this->input->urlSegment(1)"; $this->sanitizer->text($this->input->urlSegment(1)); $r->page_segment = "{$this->input->urlSegment(1)}"; $r->save(); } $event->return = str_replace("</body>", "<p>Hello {$this->input->urlSegment(1)} World!</p></body>", $event->return); } } } I want to add a configuration option for choosing the template(s) this module should activate for, maybe an admin view, but for right now this is all I got, so that the view data can be pulled easily. I know PW can handle a great many pages, but like I've kept this module uninstalled when not developing it... though maybe if I'd just left it enabled I'd have an answer to my own question here. Because tracking page views compiles much more quickly than any other sort of page, really... Should I just be storing this data in its own table?
×
×
  • Create New...