function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Avinash Ravisankar 13Avinash Ravisankar 13 

Trying to capture UTM Parameters in Visualforce Site

Dear All,

I'm trying to pass UTM Parameters into hidden fields in my VF page. I'm not able to populate these fields at all. Could someone help out?

Visualforce Page:
 
<apex:page standardController="contact" extensions="FormController" showHeader="false" sidebar="false" standardStylesheets="false" > 
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-90589553-1', 'auto');
  ga('send', 'pageview');

</script>

 <script type="text/javascript">
// Parse the URL
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');

// Put the variable names into the hidden fields in the form.
document.getElementsById("txt_source").value = source;
document.getElementsById("txt_medium").value = medium;
document.getElementsById("txt_campaign").value = campaign;

</script>

<script type="text/javascript">
//allows number and hyphen only 
function inputLimiter(e,allow) {
            var AllowableCharacters = '';

            if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
            if (allow == 'Numbers'){AllowableCharacters='1234567890';}
            if (allow == 'NameCharacters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';}
            if (allow == 'NameCharactersAndNumbers'){AllowableCharacters='1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-\'';}
            if (allow == 'Currency'){AllowableCharacters='1234567890.';}

            var k = document.all?parseInt(e.keyCode): parseInt(e.which);
            if (k!=13 && k!=8 && k!=0){
                if ((e.ctrlKey==false) && (e.altKey==false)) {
                return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
                } else {
                return true;
                }
            } else {
                return true;
            }
        } 
</script>



 <apex:form style="background-color:white">
 <a class="button" href="http://www.omniyat.com/project/thesterling/" target="_blank" style="background-color:black;font-weight:normal; size:14pt font-family:Verdana;">LEARN MORE</a>
  <div class="header">
   
 <a href = "http://www.omniyat.com/project/thesterling/" target="_blank"><img src = "https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjgQ&oid=00D7E0000000gNx&lastMod=1484130597000" align="left" />
 </a>
 
 </div>
 </apex:form>

 <br/>
 <br/>
 <br/>
 <br/>
 <br/>

 <apex:form style="background-image: url('https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjwE&oid=00D7E0000000gNx&lastMod=1484176938000');background-size:cover ">

 <body>
 
<br/>

  <div align = "right" Style="margin-right: 5cm;font-family:Verdana;font-size:16pt;">REGISTER FOR MORE INFO</div>
 <div align = "right" Style="margin-right: 4cm;">
<apex:panelGrid columns="1" > 
 
 <apex:inputfield styleclass="in" value="{!con.FirstName}"  html-placeholder="&nbsp;First Name&#8727;" style="width: 360px; height: 40px" /> 
 <apex:outputText value="{!inputTextErrorMessage}" rendered="{!IF(con.FirstName = '', true, false)}" style="color:red"/>
 <br/>
 <apex:inputField styleclass="in" value="{!con.LastName__c}" html-placeholder="&nbsp;Last Name&#8727;" style="width: 360px; height: 40px" /> 
  <apex:outputText value="{!inputTextErrorMessage2}" rendered="{!IF(con.LastName__c = '', true, false)}" style="color:red"/><br/>
 </apex:panelGrid>

  <apex:panelGrid columns="2" > 
  <apex:inputField styleclass="in" value="{!con.Country_Code__c}" style="width: 120px; height: 40px" />
  
 
 <apex:inputField styleclass="in" value="{!con.ContactPhone__c}" onkeypress="return inputLimiter(event,'Numbers');" id="Phone" html-placeholder="&nbsp;Mobile Number&#8727;" style="width: 235px; height: 40px" />
 </apex:panelGrid>
 <apex:outputText value="{!inputTextErrorMessage4}" rendered="{!IF(OR(con.ContactPhone__c = null,con.Country_Code__c = 'CountryCode*'), true, false)}"  style="color:red"/><br/>
 <apex:panelGrid columns="1" > 
 <apex:inputField styleclass="in" value="{!con.email}" html-placeholder="&nbsp;Email Address&#8727;" style="width: 360px; height: 40px" /> 
 <apex:outputText value="{!inputTextErrorMessage5}" rendered="{!IF(con.email = '', true, false)}" style="color:red"/><br/>
 <apex:inputField styleclass="in" value="{!con.Nationality__c}" html-placeholder="&nbsp;Nationality&#8727;" style="width: 364px; height: 40px"/>
 <apex:outputText value="{!inputTextErrorMessage6}" rendered="{!IF(con.Nationality__c = 'Nationality*', true, false)}" style="color:red"/><br/>
 <apex:inputField styleclass="in" value="{!con.Preferred_Time_to_Call__c}" style="width: 364px; height: 40px"/>
 <apex:inputHidden value="{!con.Visitor_ID__c}" />
 <apex:inputHidden value="{!con.Source__c}" id="txt_source" />
 <apex:inputHidden value="{!con.Campaign__c}" id="txt_campaign_name"/>
 <apex:inputHidden value="{!con.Content__c}" id="txt_content" />
  <apex:inputHidden value="{!con.Medium__c}" id="txt_medium" />
 <apex:inputHidden value="{!con.Count_of_Sessions__c}" />
 <apex:inputHidden value="{!con.Count_of_Pageviews__c}"/>


 <br/>
  <div class="g-recaptcha" data-sitekey='6LfhchEUAAAAADq1zE8wGqviN92b2IemvHSEmvuK'></div>
        <script src='https://www.google.com/recaptcha/api.js'></script>
         <apex:outputText value="{!inputTextErrorMessage3}" style="color:red"/>   
        <br/>               
        
 
 </apex:panelGrid> 
 
<span style="color:black;font-size:16pt;margin-right: 3cm;font-weight:bold;font-family:Verdana;">AGENT&nbsp;&nbsp;&nbsp; 
<apex:inputCheckbox value="{!con.Agent__c}" styleClass="myCheckBox" /></span> 
<apex:commandButton style=" margin-right: 1cm;; background:#c00;width:75px;height:30px;color:white;font-size:12pt;" action="{!submit}" value="Submit" /></div>

 <p></p><br/><br/>
 <script src='https://www.google.com/recaptcha/api.js'></script> 
 </body>
 </apex:form> 
 <br/>
 <apex:form >
 <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvL&oid=00D7E0000000gNx&lastMod=1484163217000" style="width:100%"/>
 </apex:form> 
 <br/>
<center> <h2>Visit Sterling show apartment on level 26, One by Omniyat Tower, Business Bay</h2></center>
  <apex:form >
  <apex:panelGrid columns="3" > 
 <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvQ&oid=00D7E0000000gNx&lastMod=1484164048000" style="width:33%"/>
 <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ejva&oid=00D7E0000000gNx&lastMod=1484164450000" style="width:33%"/>
 <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvV&oid=00D7E0000000gNx&lastMod=1484164361000" style="width:33%"/>
 </apex:panelGrid> 
 </apex:form> <br/>
 <apex:form >
 <img src = "https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ejvf&oid=00D7E0000000gNx&lastMod=1484167712000"  style="width:100%"/>

 
 </apex:form>
 


 
<center><img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ei3I&oid=00D7E0000000gNx&lastMod=1484172389000"/>
</center>
<center>
<p3>For further information, contact one of our sales executives or <br/>
call us on 800 666 or email at sales@omniyat.com</p3><br/></center>
<br/>
 
   <script src='https://www.google.com/recaptcha/api.js'></script> 
   <style> 
   h1
   { 
   color:white; 
   font-size:18pt; 
   } 
     h2
   { 
   align:center;
   color:grey; 
   font-size:18pt; 
   }
    h3
   { 
   align:right;
   color:black; 
   font-size:16pt; 
   }
   p
   { 
   color:black; 
   font-size:18pt; 
   }
   p5
   { 
   color:red; 
   font-size:10pt; 
   }
   p3
   { 
   color:black; 
   font-size:14pt; 
    text-align: center;
   }
   .in
   {
   
   font-size:10pt;
   color:white;
   width:82%;
   background-color:black;
   } 
   label
   {
   display: block;
   width: 150px;
   color:#ffffff;
   font-family:"Verdana"
   }
   .button {
    display: block;
    width: 115px;
    height: 25px;
    background: #4E9CAF;
    padding: 10px;
    text-align: center;
    border-radius: 5px;
    color: white;
    font-weight: bold;
     float:right;
}
   input[type=checkbox] 
   { 
   border: 0px;
   width: 2%; 
   height: 2em; 
   background-color: #ffa500; 
   } 
   @-ms-viewport{
  width: device-width;
}

header {
background-color:white;
                               
                           }
 

}
   </style>
   </apex:page>


Thanks,

Avinash

bob_buzzardbob_buzzard
The id of this field:
 
<apex:inputHidden value="{!con.Source__c}" id="txt_source" />

isn't 'txt_source', but your JavaScript assumes that it is. When you specify an ID on a Visualforce component, this is used as the final part of a system generated id. You can read all about how Visualforce IDs are generated and how to access them at:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_best_practices_accessing_id.htm