Google Tag Manager Selector для динамического класса - PullRequest
0 голосов
/ 01 октября 2019

Я пытаюсь сохранить значение href как переменную DOM GTM. Вот исходный код.

    <div class="top-menu-bar">
            <div class="container">
                <div class="top-menu">
                                            <div class="menu-ar-secondary-menu-container"><ul id="menu-ar-secondary-menu" class="menu"><li id="menu-item-818" class="mobile_menu top-menu-btn orange menu-item menu-item-type-custom menu-item-object-custom menu-item-818"><a href="https://apply-gm.sample.com/?lang=AR">افتح حساب حقيقي</a></li>
<li id="menu-item-819" class="mobile_menu top-menu-btn grey menu-item menu-item-type-custom menu-item-object-custom current-menu-item menu-item-819"><a href="https://www.sample.com/gm/ar/forex-demo-account/">افتح حساب تجريبي</a></li>
<li id="menu-item-820" class="mobile_menu top-menu-btn blue topmenuuser-icon menu-item menu-item-type-custom menu-item-object-custom menu-item-820"><a href="http://portal-gm.sample.com/login.php?lang=AR">بوابة العميل</a></li>
<li id="menu-item-821" class="pll-parent-menu-item menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-821"><a href="#pll_switcher"><span style="margin-right:0.3em;">العربية</span></a>
<ul class="sub-menu">
    <li class="lang-item lang-item-14 lang-item-id lang-item-first menu-item menu-item-type-custom menu-item-object-custom menu-item-821-id"><a href="https://www.sample.com/gm/id/forex-demo-account/" hreflang="id-ID" lang="id-ID"><span style="margin-right:0.3em;">Bahasa Indonesia</span></a></li>
    <li class="lang-item lang-item-20 lang-item-ms menu-item menu-item-type-custom menu-item-object-custom menu-item-821-ms"><a href="https://www.sample.com/gm/ms/forex-demo-account/" hreflang="ms-MY" lang="ms-MY"><span style="margin-right:0.3em;">Bahasa Melayu</span></a></li>
    <li class="lang-item lang-item-24 lang-item-ph menu-item menu-item-type-custom menu-item-object-custom menu-item-821-ph"><a href="https://www.sample.com/gm/ph/forex-demo-account/" hreflang="tl" lang="tl"><span style="margin-right:0.3em;">Tagalog</span></a></li>
    <li class="lang-item lang-item-28 lang-item-vi menu-item menu-item-type-custom menu-item-object-custom menu-item-821-vi"><a href="https://www.sample.com/gm/vi/mo-tai-forex/" hreflang="vi" lang="vi"><span style="margin-right:0.3em;">Tiếng Việt</span></a></li>
    <li class="lang-item lang-item-32 lang-item-ur menu-item menu-item-type-custom menu-item-object-custom menu-item-821-ur"><a href="https://www.sample.com/gm/ur/forex-demo-account/" hreflang="ur" lang="ur"><span style="margin-right:0.3em;">اردو</span></a></li>
    <li class="lang-item lang-item-40 lang-item-th menu-item menu-item-type-custom menu-item-object-custom menu-item-821-th"><a href="https://www.sample.com/gm/th/forex-demo-account/" hreflang="th" lang="th"><span style="margin-right:0.3em;">ไทย</span></a></li>
    <li class="lang-item lang-item-44 lang-item-jp menu-item menu-item-type-custom menu-item-object-custom menu-item-821-jp"><a href="https://www.sample.com/gm/jp/forex-demo-account/" hreflang="ja" lang="ja"><span style="margin-right:0.3em;">日本語</span></a></li>
    <li class="lang-item lang-item-48 lang-item-zh-hant menu-item menu-item-type-custom menu-item-object-custom menu-item-821-zh-hant"><a href="https://www.sample.com/gm/zh-hant/forex-demo-account/" hreflang="zh-TW" lang="zh-TW"><span style="margin-right:0.3em;">繁體中文</span></a></li><li class="lang-item lang-item-001 lang-item-hi menu-item menu-item-type-custom menu-item-object-custom menu-item-770-hi"><a href="https://www.chinese-sample.com/" hreflang="zh-hans" lang="zh-hans"><span style="margin-left:0.3em;">简体中文</span></a></li>
    <li class="lang-item lang-item-52 lang-item-ko menu-item menu-item-type-custom menu-item-object-custom menu-item-821-ko"><a href="https://www.sample.com/gm/ko/forex-demo-account/" hreflang="ko-KR" lang="ko-KR"><span style="margin-right:0.3em;">한국어</span></a></li>
    <li class="lang-item lang-item-2 lang-item-en menu-item menu-item-type-custom menu-item-object-custom menu-item-821-en"><a href="https://www.sample.com/gm/en/forex-demo-account/" hreflang="en-GB" lang="en-GB"><span style="margin-right:0.3em;">English</span></a></li>
    <li class="lang-item lang-item-5 lang-item-hi menu-item menu-item-type-custom menu-item-object-custom menu-item-821-hi"><a href="https://www.sample.com/gm/hi/forex-demo-account/" hreflang="hi-IN" lang="hi-IN"><span style="margin-right:0.3em;">हिन्दी</span></a></li>
</ul>
</li>
</ul></div>                                 </div>
            </div>
        </div>  

Проблема, с которой я сталкиваюсь, заключается в том, что числа в классах меняются, и я хочу использовать только "lang-item-ur ", который является единственным статическим элементом в приведенном выше html.

селектор, который я использую, является

#menu-item-821 > ul > li.lang-item.lang-item-32.lang-item-ur.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-821-ur > a 

, это не будет работать, потому что числа сохраняют изменения.

как я могу решить это.

1 Ответ

0 голосов
/ 01 октября 2019

Мне удалось решить эту проблему, я использовал [hreflang='ur'] с именем атрибута href

...