Difference between revisions of "Tracking radio buttons"
(Created page with 'or, "Is it possible to track radio buttons on a form as to whether they're checked or not?" If you want to track a radio button on a form, there are two methods you can use: * …') |
|||
Line 14: | Line 14: | ||
You would change it to: | You would change it to: | ||
− | <input name="newsletter" type="radio" class="inputCheckBox" value="Yes" checked="checked" onclick="if ( | + | <input name="newsletter" type="radio" class="inputCheckBox" value="Yes" checked="checked" onclick="if (window.__CR) { __CR.track('XXX','',this.value); }" /> |
This, will track when the element is checked, and pass the value "Yes" to our servers. | This, will track when the element is checked, and pass the value "Yes" to our servers. | ||
Line 44: | Line 44: | ||
You pass the item you want to check the value of (in this case "newsletter") in the [[onsubmit]] method of the form tag. This will save and submit the selected value to [[ConversionRuler]]. | You pass the item you want to check the value of (in this case "newsletter") in the [[onsubmit]] method of the form tag. This will save and submit the selected value to [[ConversionRuler]]. | ||
− | '''Very Important:''' In the above examples, you will need to change the value XXX to your action code. This can be determined by looking at the "Code Generator" page and reviewing the value within | + | '''Very Important:''' In the above examples, you will need to change the value XXX to your action code. This can be determined by looking at the "Code Generator" page and reviewing the value within __CR.track. |
'''Also Very Important:''' For the above examples to work, you must have a landing snippet or action snippet on the page. | '''Also Very Important:''' For the above examples to work, you must have a landing snippet or action snippet on the page. | ||
==See also== | ==See also== | ||
− | * [[ | + | * [[__CR.track]] |
− | * [[ | + | * [[__CR.link]] |
− | * [[ | + | * [[__CR.submit]] |
[[Category:ConversionRuler]] | [[Category:ConversionRuler]] | ||
[[Category:ConversionRuler Installation]] | [[Category:ConversionRuler Installation]] | ||
[[Category:ConversionRuler Tracking]] | [[Category:ConversionRuler Tracking]] |
Latest revision as of 15:40, 26 February 2016
or, "Is it possible to track radio buttons on a form as to whether they're checked or not?"
If you want to track a radio button on a form, there are two methods you can use:
- Track clicks on individual buttons
- Track the form when the user submits it to your site
Tracking every click
The first method is straightforward. Given a form containing:
<input name="newsletter" type="radio" class="inputCheckBox" value="Yes" checked="checked" />
You would change it to:
<input name="newsletter" type="radio" class="inputCheckBox" value="Yes" checked="checked" onclick="if (window.__CR) { __CR.track('XXX',,this.value); }" />
This, will track when the element is checked, and pass the value "Yes" to our servers.
This also means it will not track when it's unchecked, or deselected. However, for some sites this may suffice, as it's simple to implement.
Tracking when the form is submitted
The second method is slightly more complex, as it requires adding more JavaScript to your page:
<script type="text/javascript"> function track_checkbox_value(f, form_item_name) { var track_value = '-- Not checked --'; for (var i = 0; i < f.elements.length; i++) { if (f.elements[i].name == form_item_name) { if (f.elements[i].checked) { track_value = f.elements[i].value; } } } return cr_submit(f, 'XXX','',track_value); } </script> <form method="post" action="form.html" onsubmit="return track_checkbox_value(this, 'newsletter')"> <input name="newsletter" type="radio" class="inputCheckBox" value="Yes" checked="checked" /> <input name="newsletter" type="radio" class="inputCheckBox" value="No" /> <input type="submit" /> </form>
You pass the item you want to check the value of (in this case "newsletter") in the onsubmit method of the form tag. This will save and submit the selected value to ConversionRuler.
Very Important: In the above examples, you will need to change the value XXX to your action code. This can be determined by looking at the "Code Generator" page and reviewing the value within __CR.track.
Also Very Important: For the above examples to work, you must have a landing snippet or action snippet on the page.