Avatar of quokkasys
quokkasys
 asked on

Finding a way to track click throughs without losing http_referer

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
ColdFusion LanguageJavaScriptAJAXWeb DevelopmentWeb Development Software

Avatar of undefined
Last Comment
quokkasys

8/22/2022 - Mon
gheist

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.
quokkasys

ASKER
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.
gheist

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jason C. Levine

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.
quokkasys

ASKER
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.
ASKER CERTIFIED SOLUTION
Rob

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
quokkasys

ASKER
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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Rob

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?
quokkasys

ASKER
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?
Rob

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 https://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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
gheist

You can store entrance page in a session parameter or hash it into user cookie, then reuse it where needed.
_agx_

(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

Rob

Thanks _agx_! :-) I wouldn't know where to begin with cf.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
_agx_

@RobJurd - You're welcome :)
quokkasys

ASKER
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.
Rob

No problem. Any clarification you need, just ask.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Gary

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.
quokkasys

ASKER
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.
quokkasys

ASKER
Please take my previous note as an objection.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.