Solved

Finding a way to track click throughs without losing http_referer

Posted on 2014-11-14
21
130 Views
Last Modified: 2015-01-16
At my travel site (see www.travelinbc.com/vancouver.cfm) the <a href> for many of the listings go to logit.cfm.  (e.g. includes/logit.cfm?id=113&type=1&site=http://www.collegehostel.com/)

However, logit.cfm uses cflocation (in a cfc) which strips the http_referer value.  This in turn does not allow the analytics program at the destination website to register the value.  

What I'm looking for is a new way to register the click through as is done currently but also redirect the click through in a way that lets the receiving website see it.

The version of ColdFusion is 7.0 MX

From an SEO perspective, the cflocation code is not letting the other website see the click through.  We want that, but we want the stats in our database.

One theory that I've heard is that we should be able to do this with javascript so that when an on click event occurs, the INSERT could be run without interfering with the http_referer.
logit.txt
cfc-func-cflocation.txt
0
Comment
Question by:quokkasys
  • 7
  • 5
  • 3
  • +3
21 Comments
 
LVL 61

Expert Comment

by:gheist
ID: 40459824
Most likely you need to include code of logit.cfm in a page (or plainly log referer in access logs?) to capture referer without adding extra burden on a customer browser.
BTW Coldfusion 7 is EOL for couple of years.
Macromedia ColdFusion       7.x.x               2/7/2005       2/7/2010       2/7/2012
If you read intro paragraph of this:
https://en.wikipedia.org/wiki/ColdFusion_Markup_Language
You might save some cent on upgrade.
0
 

Author Comment

by:quokkasys
ID: 40460299
Upgrading CF is not a viable option at this time.  In addition, my assumption is that the entire logit.cfm code has to be replaced because cflocation regardless of version strips the http_referer.
0
 
LVL 61

Expert Comment

by:gheist
ID: 40460365
Referer: only arrives to main page reached, images and other page components are loaded from that page and have it as a referer. It should be possible to use standard access log to collect referers.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40471309
What I'm looking for is a new way to register the click through as is done currently but also redirect the click through in a way that lets the receiving website see it.

cflocation is not your friend here.  Not sure if there is an answer that will work that allows you to continue using it.  What you could do is a convoluted double redirect: Send the click to logit.cfm, then have logit send to a second script that does a simple javascript window.location or or <meta http-equiv="refresh" content="<2;url=http://go.somewhere.com>"> or other form of AJAX action to send the user on their way.
0
 

Author Comment

by:quokkasys
ID: 40471891
Yes. I am assuming cflocation has to go away. Is there any javascript that could fire off the cfm or cfc function while leaving the a href as normal?

E.g. Onclick event -> does INSERT INTO independently of the a href.
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 40472722
From purely the javascript side (my CF is VERY limited).

I'm going to use jQuery to simplify the javascript, you will need to include this tag in the head section of your site:
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>

I'm going to assume you have a simple CF script that takes does the INSERT INTO when the link is clicked:

Demo here: http://jsbin.com/socoyu/1/edit?html,js,console,output

Also within <script> tags:

$(function() {
	$('a').on('click', function(e) {
		e.preventDefault();
		var me = this;
		$.ajax({
			url:'update_db_cf_script.cfm',
			data: {
				name: 'value go here',
				nextvar: 'something else'
			},
			method: 'POST',
			success: function(data) {
				// this is called after the script has completed and updated the database
              console.log($(me).attr('href'));
				//$(me) is the original link
			}
		})
	});
});

Open in new window

0
 

Author Comment

by:quokkasys
ID: 40472942
To Rob:

IDEA:  Let's go pure Javascript on this.  Can an <a href> that looks like this:

<a href="http://www.seaviewbeachresort.com/" name="544" onClick="LogFunction();">Seaview Beach Resort</a>

have the LogFunction write "544,2014-11-30 09:09:59" to a clicklog.txt text file on the server?  The 544 is the unique identifier and the current date and time.

This would eliminate Coldfusion calls completely and I could write a batch process interrogate the log file and load the data I need.  That does is not required in real time.

At this point my javascript skills fall off the ledge.  I worry about contention to the log file as lots of people could be calling the javascript function at the same time.  Can you help?
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40473016
quokkasys,

Let's see how we go.

 JavaScript runs on the client so consequently does not have access to your server.  JavaScript will need to call (via ajax) a server side scripting language e.g. ColdFusion/php/asp/whatever and that script had to write the log file.
As you're using ColdFusion, create a simple script that takes a request parameter and writes it to a file. JavaScript passes the variable via ajax.
Does that make sense so far?
0
 

Author Comment

by:quokkasys
ID: 40475299
It makes sense, but where I run a-ground is with Coldfusion.  I don't know how to run something server side without posting to a .cfm.  This tends to interfere with the a href post to another page.  Is there a way to execute a script without posting to a CFM?  I can write the CF code, but how does javascript -> Ajax -> Coldfusion?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40475363
We will need to post to a .cfm but it will be done via ajax meaning the page doesn't reload, it does it in the background (asynchronous).  Let's give that a try.  I'd also suggest we use jQuery as it will make this process VERY simple (which is nothing but pure javascript http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_12264-Javascript-Frameworks-what-are-they.html).

Please refer back to my comment above http:#a40472722 as I would only be repeating it again here.  That code is javascript -> Ajax -> Coldfusion
0
 
LVL 61

Expert Comment

by:gheist
ID: 40475441
You can store entrance page in a session parameter or hash it into user cookie, then reuse it where needed.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40476261
(no points, I've gotta run ...)

I agree with Rob. You could easily adapt his example to send the information to a cfc. Then perform the db insert (or whatever you need) inside the cffunction.   Here's an adaptation of Rob's example. It invokes a cfc method and writes the 2 parameters to a file. Obviously you can change the cffunction to do whatever you want.

JQuery:
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(function() {
	$('a').on('click', function(e) {
		e.preventDefault();
		var me = this;
		$.ajax({
			url:'/path/to/YourComponent.cfc?method=logClick',
			data: {
                                // note - the parameter names should match the cfargument names 
				linkClicked: $(me).attr('href'),
				someParam: $(me).attr('name')
			},
			method: 'POST',
			success: function(data) {
				alert('done');
				// this is called after the script has completed and updated the database
              console.log($(me).attr('href'));
				//$(me) is the original link
			},
			error: function (content) {
		        alert(content.responseText);
		    }			
		})
	});
});
</script>                                          

<a href="http://blahblah.com name="544">Click to test</a>

Open in new window


/path/to/YourComponent.cfc

<cfcomponent>
	<cffunction name="logClick" access="remote" returntype="void" output="false">
		<cfargument name="linkClicked" type="string" required="true" />
		<cfargument name="someParam" type="string" required="true" />
		
		<!--- for demo purposes, just log the values to a file --->
		<cfset local.text = now() &": linkClicked="& arguments.linkClicked &"&someParam="& arguments.someParam>
		<cffile action="append" file="c:/temp/logClick.log" output="#local.text#" />

		<!--- do database insert, etc... here ---->
	</cffunction>
</cfcomponent>

Open in new window

0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40476905
Thanks _agx_! :-) I wouldn't know where to begin with cf.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40478458
@RobJurd - You're welcome :)
0
 

Author Comment

by:quokkasys
ID: 40483523
I am going to work on testing a combination of these ideas over the weekend.  I will report back with results.  Thanks for your help.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40483870
No problem. Any clarification you need, just ask.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40521989
I've requested that this question be closed as follows:

Accepted answer: 500 points for Rob Jurd's comment #a40472722

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:quokkasys
ID: 40521987
Please do not close this question as I have yet to test or implement the code suggestions due to Christmas and New Year's holidays and staff shortages.  My target is Jan 10/15.  Please advise.
0
 

Author Comment

by:quokkasys
ID: 40521990
Please take my previous note as an objection.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now