Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created July 6, 2015 21:07
Show Gist options
  • Save stevewithington/23f5670ce169065dfe6a to your computer and use it in GitHub Desktop.
Save stevewithington/23f5670ce169065dfe6a to your computer and use it in GitHub Desktop.
Mura CMS : Get page views ...
<!---
I recommend using Google Analytics or some other service to track and obtain page view data.
This is due to the fact that tracking session data can be expensive as far as database resources, and bandwidth ...
and the higher the number of days you track, the greater potential for running into performance issues.
Because of this, I usually recommend that clients set this to zero (0) and use an alternate way to obtain this data.
However, if you insist, follow the instructions below ...
--->
<!--- in your /config/settings.ini.cfm file, look for the following --->
sessionhistory=1
<!--- This is the number of days to track sessions --->
<!--- Drop this method in your Site or Theme contentRenderer.cfc --->
<cffunction name="getPageViews" returntype="any" output="false">
<cfset var rs = '' />
<cfquery name="rs" datasource="#$.globalConfig('datasource')#">
SELECT COUNT(*) hits
FROM tsessiontracking
INNER JOIN tcontent
ON (tsessiontracking.contentID=tcontent.contentID)
WHERE tsessiontracking.contentid=<cfqueryparam cfsqltype="cf_sql_varchar" value="#$.content('contentid')#" />
</cfquery>
<cfreturn rs.hits />
</cffunction>
<!--- Then, to obtain page views, use --->
<cfoutput>
#$.getPageViews()#
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment