- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
10-15-2014 11:03 AM - last edited on 10-05-2015 09:34 AM by kathleen_jo
I'm looking to dynamically track the input ID value of navigation facets in the event label field in Google Analytics.
An extension is setup where the event label is set to this JS code:
jQuery(document).ready(function () { jQuery(":checkbox").change(function(){ jQuery('input[type="checkbox"]:checked').next('label').text(); }); });
Example Input:
However, the event label is returning [object Object] instead of the ID value Special Offers-New. What am I doing wrong?
10-15-2014 11:41 AM - last edited on 10-05-2015 09:29 AM by kathleen_jo
Jesse,
Your current code is looking for the text value of the first label following the first checked checkbox.
To grab the id of the checkbox changed, you would use:
jQuery(document).ready(function () {
jQuery(":checkbox").change(function(){
jQuery(this).attr('id');
});
});
If you only want the id when the box is checked (rather than unchecked), you can check for a checked status:
jQuery(document).ready(function () {
jQuery(":checkbox").change(function(){
if (jQuery(this).is(':checked')){
jQuery(this).attr('id');
};
});
});
10-15-2014 11:57 AM - last edited on 10-05-2015 09:30 AM by kathleen_jo
Thanks for the quick reply Dave. I tried both code examples in the extension and am still receiving the [object Object] value in the event label.
The issue might be that once selected the input ID actually disappears on the page and is replaced by an <li>.
In my example:
<input type="checkbox" id="Special Offers-New" name="check" value="/browse/someurl/">
Changes to:
<li><label>Special Offers-New</label></li>
10-15-2014 01:11 PM - last edited on 10-05-2015 09:31 AM by kathleen_jo
Jesse,
You mentioned this is in a javascript extension. Are you manually calling utag.link()?
You will want to fire the manual event tracking using utag.link(), passing in the event-related values. The attributes below (event category, action and label) might be named differently in your profile. If you are not sure, you can check the Google Analytics mapped values in the tag config:
jQuery(":checkbox").change(function(){
if (jQuery(this).is(':checked')){
utag.link({
'event_category' : 'Some Value',
'event_action' : 'Some Action',
'event_label' : jQuery(this).attr('id')
});
};
});
If you wanted to capture all clicks, regardless of checkbox state, you could use Tealium's jQuery onHandler extension, like in the image I posted in the other reply.
10-05-2015 09:33 AM
Copyright All Rights Reserved © 2008-2023