Piwik Web Analytics Essentials A complete guide to tracking visitors on your websites, e-commerce shopping carts, and apps using Piwik Web Analytics Stephan A. Miller [ PUBLISHING 1 open source' I community experience distilled BIRMINGHAM - MUMBAI
Preface 1 Chapter 1: Installation and Setup 7 Meeting system requirements 8 Downloading Piwik 9 Downloading Piwik with SSH 10 Uploading to a web hosting account 11 Uploading using cpanel or other file managers 11 Uploading using FTP Creating a database for your installation 16 Creating a user and database for Piwik in cpanel 16 Creating a user and database for Piwik with phpmyadmin 18 Creating a user and database for Piwik with SSH 20 Using the Piwik installation wizard 21 Securing Piwik 27 Backing up Piwik 29 Updating Piwik 30 Using Piwik for high traffic websites 34 Dedicated server 34 Adding RAM 34 PHP caching 34 Nginx or lighttpd 35 Cron your archiving 35 Disabling real-time reports 35 Deleting old logs 36 Load balancers and multiple servers 36 Limiting tracked URLs 36 Summary 37 14
Chapter 2: Using Piwik's Interface and Reports 39 Navigating the Piwik interface 40 Using Piwik's Menus 41 The Sign In menu 41 The top bar 42 The main menu 42 Customizing the dashboard 44 Changing the dashboard layout 44 Setting a date range 46 Adding widgets to the dashboard 47 Moving and removing widgets 48 Finding the right report widget for the job 49 Visitors 49 Actions 50 Referrers 51 SEO 52 Visitor settings 52 Goals 53 Visits Summary 53 Live! 54 Reading a Piwik report 55 Customizing graph metrics 56 Managing e-mail reports 58 Summary 62 Chapter 3: Tracking Visitors with Piwik 63 Using the Piwik JavaScript tracking code 63 Functioning of default JavaScript 66 Triggering page views manually 68 Customizing page names 70 Customizing tracking URLs 71 Configuring Piwik's tracking cookies 72 Setting up download and outlink tracking 76 Disabling link tracking 76 Triggering link tracking 77 Downloading file extensions 78 The download/outlink pause timer 79 Using other Piwik JavaScript API methods 79 setrequestmethod(method) 79 discardhashtag(bool) 80 setcountprerendered(bool) 80
setdonottrack(bool) 80 killframe() 81 redirectfile(url) 81 setheartbeattimer(minumuin\/isitlength,heartbeatdelay) 81 getvisitorld() 82 getvisitorlnfo() 82 Using multiple trackers 82 Using asynchronous tracking 83 Summary 86 Chapter 4: Setting Up and Tracking Goals 87 Defining goals 88 Desired actions 89 Conversions and conversion rate 90 Setting up goals in Piwik 91 Setting up revenue tracking 94 Triggering conversions manually 97 Viewing Goals overview reports 105 Using goal detail reports 110 Analysing reports 111 Summary 112 Chapter 5: Tracking Marketing Campaigns 113 Tracking campaigns using URL parameters 114 Tracking paid searches 119 Using Google ValueTrack 120 Using Microsoft Ad Center dynamic text 122 Using Yahoo! Search Marketing's URL tagging 123 Creating campaign URLs the easy way 124 Tracking social media campaigns 126 Campaign tagging and tracking tips 127 Attributing visits to the correct campaign 128 Customizing campaign parameters 129 Viewing campaign reports 130 Summary 132 Chapter 6: Tracking Events 133 Tracking events with Piwik 134 Tracking social engagement 138 Tracking content sharing 139 Tracking blog comments 143 Tracking e-commerce events 146
Tracking Flash events 148 Tracking events with ActionScript 2 149 Tracking events with ActionScript 3 149 Tracking page load time 150 Reading custom variable reports 152 Other uses for custom variables 154 Summary 154 Chapter 7: E-commerce Tracking 155 Enabling e-commerce tracking for your website 156 Tracking orders and products purchased 159 Tracking shopping carts and items in them 162 Tracking product and category page views 164 Adding Piwik e-commerce tracking to ZenCart 165 Creating functions in PHP to mirror Piwik's functions 166 Mixing PHP andjavascript 172 Reading and using Piwik's e-commerce reports 174 A note about SSL 183 Summary 184 Chapter 8: Piwik Website and User Administration 185 Changing your Super User settings 186 Creating users in Piwik 188 Managing website access 190 Who is a Super User? 191 What are admin permissions? 192 What are view permissions? 192 Managing websites 192 Adding a website 192 Editing or deleting a website 194 Editing the global website settings 195 Tracking multiple domains or subdomains with one website account 196 Setting up an intranet as a website in Piwik 197 Turning Piwik into a white label analytics solution 198 Allowing user sign up with the Piwik Signup plugin 202 Installing a Piwik plugin 203 How the user Signup plugin works 205 Summary 207 Chapter 9: Advanced Tracking and Development 209 Tracking visitors with image tracking 210 Simple image tracking 211 Image tracking limitations 214
Advanced image tracking 214 Adding page titles to ebay auction tracking 215 Tracking a goal with an image 217 Tracking visitors with the PHP tracking API 219 Generating the image tracker 221 Making an HTTP request to the tracker 225 Tracking visitors with other programming languages 226 Java 226 Python 227 Silverlight 227 Flash 227 Using Piwik's tracking API directly 227 Debugging your tracking code 230 Piwik plugins 233 How Piwik works 233 The anatomy of a plugin 234 Writing a simple Piwik plugin 235 Summary 238 Chapter 10: Piwik Integration 239 CMS plugins 239 Piwik Mobile 243 Embedding Piwik widgets 246 Give your anonymous user rights 246 Choosing your widget 247 The Dashboard widget 248 The All Websites widget 249 Choose your own widget 250 Accessing Piwik's data 252 How to call the analytics API 252 Calling the analytics API using REST 253 Calling the analytics API locally 256 Including graphs 260 Using the Live! API 262 Segmentation 264 Creating a change log for your website with analytics feedback 266 Summary 273 Appendix A: Tracking API Reference 275 The Piwik tracking API 275 Variables 275 Methods 275 Constructor construct 275 addecommerceltem 276
disablecookiesupport 276 dotrackaction 276 dotrackecommercecartupdate 277 dotrackecommerceorder 277 dotrackgoal 278 dotrackpageview 278 enablebulktracking 278 dobulktrack 278 getattributionlnfo 278 getbaseurl 278 getcustomvariable 279 getrequesttimeout 279 gettimestamp 279 geturltrackaction 279 geturltrackgoal 279 geturltrackpageview 280 getvisitorld 280 setattributionlnfo 280 setbrowserhascookies 280 setbrowserlanguage 280 setcustomvariable 281 setdebugstringappend 281 setecommerceview 281 setforcevisitdatetime 282 setlp 282 setlocaltime 282 setplugins 282 setrequesttimeout 283 setresolution 283 settokenauth 283 seturl 283 seturlreferrer 283 setuseragent 284 setvisitorld 284 Appendix B: Analytics API Reference 285 The Piwik analytics API 285 Module API 285 Module Actions 286 Module CustomVariables 286 Module ExampleAPI 286 Module Goals 286 Module ImageGraph 287 Module LanguagesManager 287 Module Live! 287 Module MultiSites 288 Module PDFReports 288 Module Provider 288
Module Referers 288 Module SEO 288 Module SitesManager 289 Module UserCountry 289 Module UserSettings 289 Module UsersManager 289 Module VisitFrequency 289 Module VisitTime 290 Module Visitorlnterest 290 Module VisitsSummary 290 Index 291