Create dynamic link from cookie
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We utilize a third-party software to complete a job application process. This system allows us to add a snippet of code to the end of the links to it, which then show up in tracking reports. As an example, the tracking code from a Monster.com posting may end with ?r=monster and be attributed to Monster.com. On our website, that may be ?r=corporatewebsite and be attributed back to the corporate website, etc.

Where data is lost is when people come to the corporate website to complete an application. Because the ?r= snippet is static, every application coming from the corporate website shows up with the code 'corporatewebsite.' What we would like to do is attribute it back to the referring source which sent the user to the corporate website.

A user path may look like this:

Google PPC > website > third-party application software

In this scenario, the link to the third-party application software would be coded as ?r=corporatewebsite.

What we need it to be coded as would be the source (or preferably source and medium) that is brought to the corporate site via a cookie on the user. In this case, we need the link to be dynamically built to instead read ?r=google/ppc or at the very least ?r=google.

Ideally, I'd like to carry more information from that (campaign information from the cookie), but that's a starting place.

is already loaded any javascript framework (like jquery or underscore)
andijcr almost 7 years ago
awarded to andijcr

Crowdsource coding tasks.

1 Solution

Winning solution

assuming that the link to modify in your page is in this form:

<a id="link_application" href="http:\\yourserver.com\application">job application</a>

this javascript should give you a referrer:

var referrer= document.referrer || window.location.origin;
var link=document.getElementById('link_application');
link.href += '?r='+encodeURIComponent(referrer);

but without further details, it's difficult to have it working properly in your page.

**

after the details, the correct code to insert in the page should be:

function changeReferrer(){ 
    var referrer= document.referrer || window.location.origin;
    var link=document.getElementsByClassName('btn')[0];
    link.href=link.href.replace(/r=[^&]*/, 'r='+encodeURIComponent(referrer));
}

function checkload(){
    (document.readyState !== 'complete')? setTimeout(checkload, 10) : changeReferrer();
}

checkload();

Insert this code into a script tag inside the page.

Let me know what other details you need. Here is a live page where such a link would be: http://www.drivearnold.com/ The link in the upper-right corner (Apply Online) is the one we need to change related to the cookie information. Right now it's: https://intelliapp2.driverapponline.com/c/arnoldtrans?r=drivearnold We want to populate what's behind the ?r= with the information from the cookie. Hope that helps.
semi-clueless almost 7 years ago
is it possible to modify the page, like adding a <script> tag at the end of it?
andijcr almost 7 years ago
I'm not sure what you mean. We're not so smart here. Here is a sample page on that site, to which we've added your code. http://www.drivearnold.com/z-linktest.html
semi-clueless almost 7 years ago
update the solution to work on your page
andijcr almost 7 years ago
do you know if there's any way to test this? should it pick up a referrer if i'm just bouncing back and forth on it? http://www.drivearnold.com/z-linktest4.html
semi-clueless almost 7 years ago
try to search drivearnold.com on google.com, open the page and you'll see that the link has changed to include http%3A%2F%2Fwww.google.com%2F In general this method work if the user arrive from a page like a search engine.
andijcr almost 7 years ago
Awesome. Thanks. If you know of a way to (a) shorten that so it doesn't have all the characters and (b) be able to pull from the tags that we put on links to that page (utmsource=, utmmedium=, utm_campaign, etc.), that would be outstanding. But thanks for your help so far.
semi-clueless almost 7 years ago