PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > Mod Submissions

Reply
 
Thread Tools
Old 02-07-2007, 12:27 PM   #1
dekortage
Green Mole
 
Join Date: Feb 2007
Posts: 2
Google Analytics on PDF links in search results

For a client site, I installed Google Analytics to do visitor tracking. The hosting came with some tracking, but GA includes geographic analysis and site overlays that are useful to us.

If you have used GA, you know it works like this:
- You put some JavaScript code on every web page. With a template-based site, you just add it to the template and go.
- GA automatically tracks HTML links.
- If you want GA to track file downloads (such as PDFs) then you need to tag those links with an "onClick" reference to GA's code.

This is simple enough with static or CMS-driven web pages. However, PHPdig returns PDF files in its results, without tagging them for GA. Fortunately it does tag them for the "clickit()" JavaScript function, so I modified the JavaScript code to check for files in the PDF directory and call GA's code acccordingly. In the /libs/search_function.php file, look for the clickit() function around line 675, and replace it with this:

function clickit(cn,clink) {
re = /yourdomain.com%2Fpdf%2F/gi; // search for PDF reference
if (clink.search(re) != -1) {
ulink = clink.replace(re,'/pdf/');
urchinTracker(ulink); // add to Google Analytics
}
if(document.images) {
(new Image()).src=\"clickstats.php?num=\"+cn+\"&url=\"+clink+\"&val=".urlencode( $js_string)."\";
}
return true;
}

Replace the text "yourdomain.com" with your actual domain name. In this example, the PDFs are always installed in a root directory called "/pdf". If your PDFs are in another directory, you will have change the "re" line and the "ulink" line appropriately.
dekortage is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
No most searched terms, biggest results, most 0 results, last search queries, etc. jongag1 How-to Forum 6 04-22-2005 11:43 AM
Search page to search all domains & links generally shamu How-to Forum 5 10-27-2004 02:55 PM
google like search engine sasa How-to Forum 3 09-10-2004 10:41 AM
Mid Google search or big brother? Dave A How-to Forum 3 08-16-2004 01:20 AM
Search PDF files chazter External Binaries 4 10-02-2003 07:47 AM


All times are GMT -8. The time now is 08:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.