Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #201201

    Hi,

    I’m trying to add some google analytic events to my site. They are triggered on IDs and Classes. I want to trigger an event if someone clicks on an ‘entry’ in some content contained in a tab (you know, like the accordions, but not animated).

    The problem is that each tab ‘handle’ doesn’t have a unique class or an ID. They have ‘fake IDs’ ( e.g. data-fake-id=”#tab-id-1″) and a class to say whether it’s the active tab or not, but they aren’t unique.

    Anyone got any ideas how I might set this up?

    Rob.

    #201850

    Hi Rob!

    So you’d want to apply an ID/class of “toggle-id-x” to that p element that opens the accordion?

    Regards,
    Josue

    #202018

    Not quite,

    The page I’m talking about is here: http://goo.gl/S2FB8B

    I want to set an event on the tabs so that I can track when people have opened one of the tabs, such as “company goals” or “Company objectives”.

    To do that, each tab needs a unique ID or Class that I can trigger the google event tracking code off, but they don’t have unique IDs or Classes. I was wondering how I can add them.

    Rob.

    #202199

    Hey Rob!

    They actually have numeric classes:

    If you want to target each tab section, simply prefix the parent element number class, for example:

    .avia-builder-el-6 .tab_counter_2
    

    Best regards,
    Josue

    #202203

    That’s good, but how do I set the prefix. Is there something I can do from within the page editor? Some elements have the ability to add a class to them from within the editor, but the Tab element isn’t one of them, unless I’m missing something?

    #202207

    Hi!

    That class is automatically added based in the order of the element (unique), if you are in Chrome try inspecting them so you can get the idea.

    Regards,
    Josue

    #202232

    But I have multiple tab ‘blocks’ on screen and the class is only unique for each tab within the block.

    I also have another little problem. I’m using a WP plugin to help embed the Google Event code. If the class or ID has a space in it, the plugin replaces it with a – so the final rendered page doesn’t work. I probably need to find a better one…

    #202235

    Hi,

    I got an idea, open /config-templatebuilder/avia-shortcodes/tabs.php and look for line 253:

    $output .= '    <div data-fake-id="#'.$tab_atts['custom_id'].'" class="tab '.$titleClass.'" '.$markup_title.'>'.$icon.$tab_atts['title'].'</div>'."\n";
    

    Replace it by this:

    $output .= '    <div data-fake-id="#'.$tab_atts['custom_id'].'" id="#'.$tab_atts['custom_id'].'" class="tab '.$titleClass.'" '.$markup_title.'>'.$icon.$tab_atts['title'].'</div>'."\n";
    

    That will put the data-fake-id number as ID too, this way you can target them using ID.

    Regards,
    Josue

    #202259

    Well, that *should* do it and I thank you for you patience on this one, but it doesn’t work. I’ve changed the code and the new ID is not getting added to the page. To make sure I’m not getting the old stuff cached, I cleared all the caches and I still don’t see the new ID. To make absolutely sure it’s not a caching issue, I added a syntax error to the .php code you suggested above and sure enough, that broke the site, so I know I’m using the latest version of the file.

    I’ve no idea why the code you supplied isn’t making a change to the outputted HTML…..? I’ve tried doing things like added some free text to the line e.g. $output .= ‘ HELLO <div data-fake-id=”#’.$tab_atts[‘custom_id’].’… but the HELLO isn’t getting output either. I must be missing something somewhere, I don’t really know much about all of this, I’m just hacking to see what happens. I’m sure it would make a developer cry!

    #202262

    Ignore that last post. I am now seeing the ID in the page source. No idea why, the only thing I did was this.

    Originally, I made a copy of tabs.php named one to tabs-old.php and made the edit to tabs.php. After deleting the tabs-old.php (after saving it on my local machine) the ID is now appearing!!!

    I’ll just see if I can get the events to work now….

    #202264

    YES!
    YES!
    YES!

    It works. Thank you for your support Josue, spot on.

    If anyone else finds this thread, then you need to make the change Josue suggests above and I’m using a WordPress plugin called WP Google Analytics Events Settings to help me set-up all the event triggers.

    With this change, even if you have multiple tabs on the same page, you get unique IDs so it all works.

    One thing to note though. Because the plugin adds a # to the code (when setting up the triggers), then I removed the one Josue suggests to put in, so I changed the PHP line to this:

    $output .= ‘ <div data-fake-id=”#’.$tab_atts[‘custom_id’].'” id=”‘.$tab_atts[‘custom_id’].'” class=”tab ‘.$titleClass.'” ‘.$markup_title.’>’.$icon.$tab_atts[‘title’].'</div>’.”\n”;

    Thank you.

    #202273

    You are welcome, glad we could help :)

    Regards,
    Josue

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Avia Layout Builder, Tabs and Google Event Handlers’ is closed to new replies.