- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
03-15-2016 02:34 AM
Hi Community,
I am interested in tracking if a check box on a form was selected on the time a user generate the lead. I am interested in tracking both if selected will have value 1 if not value 0.
I have seen this post https://community.tealiumiq.com/t5/Tealium-iQ/Dynamic-Google-Analytics-Event-Label-Input-ID-Values/m...
but I am not sure this can be the solution I am after.
Thank you very much for your help.
Solved! Go to Solution.
03-15-2016 08:56 AM
Hi @defelicemattia,
That article is a good reference.
When trying out jQuery, Chrome development tools are useful. Here is an example of a checkbox with similar code applied:
I've added some feedback to the console to verify what is happening within the script. As well, I used an ID to the checkbox which can be useful if you are looking for specific elements. In this example, the checkbox was clicked three times to demonstrate the results in the Console.
Give it a try first in dev tools!
03-15-2016 10:01 AM - edited 03-15-2016 10:04 AM
Hi @david_bird
Thank you very much for your answer.
How do I use this to track users that submit a form with the check box selected or not?
In other words I need to track subscribers and not subscribers to a newsletter. Is this possible?
The check box is set by default as checked and when I uncheck it the value doesn't change.
03-15-2016 10:08 AM - last edited on 03-15-2016 11:07 AM by kathleen_jo
Hello @defelicemattia,
To test the value of the checkbox, you could look at it's property. So, for the previous example, using the checkbox with id=cbemail
$("#cbemail").prop('checked')
would return 'true' when the checkbox is checked and 'false' when it is not checked.
03-16-2016 02:41 AM
Hi @david_bird
Could you explain more in details please? Should I create a custom extension JQuery onHandler in order to capture forms sent with the checkbox checked or unchecked?
Thank you very much for your patience :)
03-16-2016 07:35 AM
Hi @defelicemattia,
Yes, you can use the 'custom' Tracking Event option in the jQuery onHandler extension. Then supply the code within the JavaScript field to gather the information needed for the utag.link/utag.view call, including the status of your checkbox.
I think we are going to need some more context in order to supply any details. Feel free to reach out to your Account Manager if you want to talk to an engineer over the phone about the specifics.
Thanks, David
03-16-2016 08:01 AM
Hi @david_bird,
thanks again for your advices, I see now the value of the check box into the console log as for your screenshot through a custom jQuery handler extension.
Now I only need to map this value to a custom dimension through either a cookie or an UDO.
could you help?
Thanks again :)
03-17-2016 05:58 AM - edited 03-17-2016 05:59 AM
Hi @david_bird
I know sometimes it is very difficult to place into context all the requirements users post on the community especially because not all the users are developer and often not familiar with custom tricks. You have anyway managed to drive me to the right direction and I have solved this and thought to share it with the community.
1-Using a jQuery handler extension in order to set the value of a variable registering interactions with the check box (thank David for the code which I just needed to modify) below the code I have used:
jQuery(document.body).ready(function () {
jQuery("#copy and paste here the checkbox id from your html code").change(function(){
if (jQuery(this).is(':checked')){ utag.link({ "UDO variable name as set into data layers tab":"checked" });
jQuery(this).attr('id');
} else utag.link({ "UDO variable name as set into data layers tab":"unchecked" });
});
});
2-Set persist value to place your UDO variable name as set into data layers tab into a cookie
3-duplicate the persist value extension and set to text as checked in order to set default value of the cookie adding the condition yourcookie is not defined
Hope this can help other users.
However, my last question is are you aware of any way to select multiple elements (check boxes) through jQuery selector as the ids all begin with the same string edit-submitted-subscribe-to-promotions
Thanks again for the support.
03-17-2016 07:38 AM
Hi @defelicemattia,
Try using jQuery wildcards for your selector. Since edit-submitted-subscribe-to-promotions is the beginning of the ID, use
jQuery('[id^=edit-submitted-subscribe-to-promotions]').change ...
If you encounter or set up a different pattern, try this reference for other wildcards:
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
Hope this helps.
~ David
03-17-2016 12:02 PM
Thank you @defelicemattia for sharing with us!
Copyright All Rights Reserved © 2008-2023