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& amp;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
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
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.
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.
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.
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.
E.g. Onclick event -> does INSERT INTO independently of the a href.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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();">S eaview 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?
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();">S
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?
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/whateve r 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?
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/whateve
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?
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?
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
Please refer back to my comment above http:#a40472722 as I would only be repeating it again here. That code is javascript -> Ajax -> Coldfusion
You can store entrance page in a session parameter or hash it into user cookie, then reuse it where needed.
(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:
/path/to/YourComponent.cfc
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>
/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>
Thanks _agx_! :-) I wouldn't know where to begin with cf.
@RobJurd - You're welcome :)
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.
No problem. Any clarification you need, just ask.
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.
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.
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.
ASKER
Please take my previous note as an objection.
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.