Is there are package that will track downloads of a pdf? If a user has a link to a pdf directly and downloads the pdf without going to a webpage, how would you track that event? WordPress has a plugin to do this and I have a client asking to do the same in Umbraco.
You will probably want to create a HttpHandler (I think that's the right thing) that can hook in nice and early into your request pipeline at an IIS level. Then you should be able to get the URL and identify if it is a PDF of not, then post a logging/tracking entry where ever you need it to be stored in order to report on it.
GA alone will not work in this instance. If a user has the direct link to a pdf like https://abc.com/filename.pdf, GA will not be able to track this. There is a WordPress plugin that does this and sends the tracking information to GA, but I can't seem to find anything like that for Umbraco. Umbraco needs to stop so much development on the CMS (every single release has bugs) and begin to provide robust packages that rival WordPress. Just to setup a shopping cart in Umbraco is a PIA while my clients are setting up carts and their own GTM tagging with WordPress.
I understand the weaknesses of WordPress, but when a client is coming from WordPress and we have to build something that WordPress already does, Umbraco doesn't look so good. No one who is making money in this business has time to create every feature from scratch.
using System;
using System.Web;
public class HelloWorldModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.LogRequest += new EventHandler(LogRequest);
}
private void LogRequest(object sender, EventArgs e)
{
//Log operation goes here
HttpContext context = ((HttpApplication)sender).Context;
string url = context.Request.Path;
if (url.ToLower().EndsWith("pdf"))
{
// log to google analytics
}
}
public void Dispose()
{
}
}
Step 2
In the web.config system.webServer section add the line below:
<add name="Files" type="HelloWorldModule" />
It should look like this:
Step 3
Change the class above to send the pdf details to google analytics. There seems to be multiple ways to do this, have a look at the developer guide in the link below:
You can actually achive it via implementing either IHttpModule or IHttpHandler. I added info regarding handler below. This requires a couple changes.
You need a class implementing IHttpHandler to grab requests
You need to add required configuration entries in web.config depending what you want to track. In your case, since you want to track pdf files in Umbraco, you need to add it into media/web.config file, not the config file on the root.
using System;
using System.Web;
namespace YourNamespace.App_Start.Handlers
{
public class FileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
switch (context.Request.HttpMethod)
{
//First make sure this is a get request
case "GET":
{
//This will give you absolute path
var absolutePath = context.Request.Url.AbsolutePath.Trim();
/*
* Now you can check the path for pdf
* Verify your file if exist
* Store it as a counter at google analytics or somewhere in db
*/
break;
}
}
}
public bool IsReusable { get; }
}
}
And then media/web.config file should look like this;
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<clear/>
<add name="PDF" path="*.pdf" verb="*" type="Yournamespace.Handlers.FileHandler" />
<!-- lines below should be there by default - at least on v7 -->
<add name="StaticFileHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler"/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either"
requireAccess="Read"/>
</handlers>
</system.webServer>
</configuration>
PS: In a project we are pushing tracking data to google analytics with a specific category.
Track downloads for links directly to PDF file.
Is there are package that will track downloads of a pdf? If a user has a link to a pdf directly and downloads the pdf without going to a webpage, how would you track that event? WordPress has a plugin to do this and I have a client asking to do the same in Umbraco.
https://carlhendy.com/pdf-analytics/
You will probably want to create a HttpHandler (I think that's the right thing) that can hook in nice and early into your request pipeline at an IIS level. Then you should be able to get the URL and identify if it is a PDF of not, then post a logging/tracking entry where ever you need it to be stored in order to report on it.
This is all theoretical though :-D
Nik
It seems like you are looking for something like this:
https://www.datadrivenu.com/track-downloads-google-analytics/
GA alone will not work in this instance. If a user has the direct link to a pdf like https://abc.com/filename.pdf, GA will not be able to track this. There is a WordPress plugin that does this and sends the tracking information to GA, but I can't seem to find anything like that for Umbraco. Umbraco needs to stop so much development on the CMS (every single release has bugs) and begin to provide robust packages that rival WordPress. Just to setup a shopping cart in Umbraco is a PIA while my clients are setting up carts and their own GTM tagging with WordPress.
Niks suggestion will work.
The power of Umbraco is that it is developer friendly. It allows developers to extend it easily.
One of the biggest benefits of WordPress is the amount of plugins. It's also it's biggest weakness.
I understand the weaknesses of WordPress, but when a client is coming from WordPress and we have to build something that WordPress already does, Umbraco doesn't look so good. No one who is making money in this business has time to create every feature from scratch.
Here's how to do it:
Step 1
Copy the class below into your code:
Step 2 In the web.config system.webServer section add the line below:
It should look like this:
Step 3
Change the class above to send the pdf details to google analytics. There seems to be multiple ways to do this, have a look at the developer guide in the link below:
https://developers.google.com/analytics/devguides/collection/protocol/v1/
I hope this helps.
Do I just need to create a class called HelloWorldModule?
Have you got .Net experience?
It depends on how the solution is set up (web site/web application) on how you'll structure the code/project.
If you create an App_Code folder in the root of the website and create the class in there it should work, regardless.
Hi,
You can actually achive it via implementing either IHttpModule or IHttpHandler. I added info regarding handler below. This requires a couple changes.
And then media/web.config file should look like this;
PS: In a project we are pushing tracking data to google analytics with a specific category.
Best, Mehmet
is working on a reply...