Hello All--
Our goal is twofold...
1. Scan a page for an area of text "ID" and then submit then place the number after said ID into a variable.
2. Pass the variable to Google Analytics.
The code we have is not working... it never finds the ID.
The script will be used on several pages, but the text to search for is always that same... that is:
ID: ## up to ID: #####
So the ID can be from 2 to 5 digits.
I'm attaching screenshots that visually display the example above.
The project shouldn't take more than an hour for the right coder. The broken/erroneous code is below:
(placed at the top of page)
<script type="text/javascript">
//Define a trim function to trim the white spaces both before and end of string
[login to view URL] = function () {
return [login to view URL](/^\s*/, "").replace(/\s*$/, "");}
//Search Function to get the ID
function GetID(){
var spans = $("span");
var i = 0;
//Define the regix object that checks the presence of both Applicant: and ID: in the string
var re = /Applicant:.+ID:.+/;
for(i = 0; i < [login to view URL]; ++i)
{ if( spans[i].[login to view URL](re))
{
return spans[i].[login to view URL]("ID:")[1].trim();
}
}
return "NOT FOUND";
}
</script>
(placed at bottom of page)
<script type="text/javascript">
var gaJsHost = (("https:" == [login to view URL]) ? "https://ssl." : "http://www.");
[login to view URL](unescape("%3Cscript src='" + gaJsHost + "[login to view URL]' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
leadID = GetID();
try {
var pageTracker = _gat._getTracker("UA-1XXXXXX-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._setCustomVar(1,"Lead_id",leadID,1);
pageTracker._setCustomVar(2,"Form_variation","CS",1);
pageTracker._trackPageview();
} catch(err) {}</script>