Solved

Finding a way to track click throughs without losing http_referer

Posted on 2014-11-14
21
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +3
21 Comments
 
LVL 62

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 62

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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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 43

Accepted Solution

by:
Rob 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 43

Expert Comment

by:Rob
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
 
LVL 43

Expert Comment

by:Rob
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 62

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 43

Expert Comment

by:Rob
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 43

Expert Comment

by:Rob
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

726 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