PDF download counter in Xenforo

I hope some developers will take on this. I'll try to play around with this.

On another note, if we have Resource manager, we can show the download count for this!!!
 
I'm thinking of other ways to accomplish this.

I will make the PDF an attachment to a post and let guests download them. I will then use the download count for this attachment and display it on sidebar or inside User Notice.

Is there a way to download this info directly?
 
Create a listener for the template_hook event:

Admin CP -> Development -> Code Event Listeners

Here is some example code:

Code:
<?php

class Class_Name
{
	public static function pdfCount($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
	{
		if ($hookName == 'forum_list_sidebar')
		{
			$db = XenForo_Application::get('db');

			$count = $db->fetchOne("
				SELECT view_count
				FROM xf_attachment
				WHERE attachment_id = 1
			");

			$contents .= "PDF viewed {$count} times.";
		}
	}
}

You can add your own includes in there if you need to use a layout file.
 
Create a listener for the template_hook event:

Admin CP -> Development -> Code Event Listeners

Here is some example code:

Code:
<?php
 
class Class_Name
{
public static function pdfCount($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'forum_list_sidebar')
{
$db = XenForo_Application::get('db');
 
$count = $db->fetchOne("
SELECT view_count
FROM xf_attachment
WHERE attachment_id = 1
");
 
$contents .= "PDF viewed {$count} times.";
}
}
}

You can add your own includes in there if you need to use a layout file.
Sounds very good, Jake.
1) Is there a list of hook names that I can use? I see that you use "forum_list_sidebar". What if I want to add it in the Notices?
2) Can you provide some example layout file and how I can use it?
Thanks very much.
 
1) Hook names are inline with the template code. Look in the template where you want to add content and you will usually see xen:hook tags.

2) You probably want to render a template and then append the output of that template to the contents of the hook. Code example:

http://xenforo.com/community/threads/have-no-idea-how-to-get-mod-working.23345/#post-306442

For layout code you can look to the other sidebar blocks such as those in:

Admin CP -> Appearance -> Templates -> forum_list
 
I'm reading this http://automateeverything.tumblr.com/post/22957300206/google-analytics-pdf-tracking-made-easy

Anyone know how I can use the url bbcode in Xenforo to link something like this?
Code:
<a onclick="_gaq.push(['_trackEvent', 'PDF', 'Download', '/some/pdf/file.pdf']);"" href="/some/pdf/file.pdf">Download this PDF</a>
I haven't read through the link but I'm fairly certain that doing so won't work for you because the counter will showup in Google Analytics dashboard but not in place. Basically you will need a custom add-on or using some external tracker service.
 
I haven't read through the link but I'm fairly certain that doing so won't work for you because the counter will showup in Google Analytics dashboard but not in place. Basically you will need a custom add-on or using some external tracker service.
Yes, I now only need to track this on Analytics and don't need XF to keep track of this. It appears the url bbcode does not allow any optional beside the http.
 
Top Bottom