1
votes

I have two tags on same page.

First tag works on page view and contains custom html that push a value to dataLayer.

<script>
  $(document).ready(function ($) {
    $('ul li').click(function(){
        console.log("index:"+$(this).index());
        dataLayer.push({'clicked_slider_tab_index': $(this).index()});
    });
  });
</script> 

And second tag firing on element click with Universal analytic type using this dataLayer variable in Label field.

Problem is that. When second tag firing it's {{dataLayer - clicked_slider_tab_index}} variable has previous value. console.log works as expected but somehow dataLayer.push is not working as expected.

I can only detect index clicked in previous action.

1

1 Answers

2
votes

This is most likely happening because the link click event is triggering both your custom HTML tag and your Universal Event tag at the same time, thus the Custom HTML tag hasnt had time to updated the 'clicked_slider_tab_index' value.

The best way to track in this instance would be to expand your dataLayer.push to include an event. The next step would be to change the trigger to fire on the new event "indexClicked". This would ensure that the dataLayer variables are populated when the element is clicked.

<script>
  $(document).ready(function ($) {
    $('ul li').click(function(){
        console.log("index:"+$(this).index());
        dataLayer.push({
        'event': 'indexClicked'
        'clicked_slider_tab_index': $(this).index()
      });
    });
  });
</script>