[Resolved] Tracking Code on specific pages?

Home Forums Support [Resolved] Tracking Code on specific pages?

Home Forums Support Tracking Code on specific pages?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #501772
    Edin

    Hello,

    What would be the preferred way if I wanted to add tracking code (one part in the header, the other part below the body tag) to specific pages or posts only?

    Like for example the FB tracking code and event tracking that I only want for a few pages of my site.

    Thanks,
    Edin

    #502118
    Leo
    Staff
    Customer Support

    Hi Edin,

    Something like this should help: https://docs.generatepress.com/article/using-hooks-conditional-tags/

    Let me know.

    #502251
    Edin

    Thank you Leo.

    So, if I wanted to add a tracking code to pages 55, 56, 57 in the header, I add this code to the wp_head hook:

    <?php if ( is_page(55, 56, 57) ) : ?>
        <script>Tracking Script</script>
    <?php endif; ?>

    Right?

    I’d have to check “Execute PHP”, would that mess up code that’s already in there but is no php?

    Thanks,
    Edin

    #502366
    Leo
    Staff
    Customer Support

    Yup code looks good.

    Nope it won’t mess with the code without PHP πŸ™‚

    #679328
    Edin

    I’ve had this working with one page since I started this thread.

    Today, however, I wanted to add another page, but for some reason, the tracking code only fires on the first specified page number.

    <?php if ( is_page(7134, 6891) ) : ?>
    	<!-- Facebook Pixel Code -->
    	<script>
    	  FB code
    	</script>
    	<noscript><img height="1" width="1" style="display:none"
    	  src="https://www.facebook.com/tr?id=x"
    	/></noscript>
    	<!-- End Facebook Pixel Code -->
    <?php endif; ?>

    So the FB-Pixel only fires on post 7134, NOT on post 6891. Any idea why?

    Thanks,
    Edin

    #679377
    David
    Staff
    Customer Support

    Try using the new Elements module for Hooks:

    https://docs.generatepress.com/article/hooks-element-overview/

    You can remove the conditional PHP now and use the Display Rules it provides.

    #679385
    Edin

    Thanks David.

    Can you point me to the article that describes how to switch from the “old” hooks system to the new elements module for Hooks? (I’ve seen it somewhere, but can’t find it again)

    #679398
    Edin

    Also, can I use both systems at the same time?

    #679401
    Leo
    Staff
    Customer Support

    Should be in our documentation page:
    https://docs.generatepress.com/article/moving-hooks-page-headers-to-elements/

    Technically you can use both but I don’t see any advantages of doing that though.

    Best to use the new one πŸ™‚

    #679472
    Edin

    I started to migrate from the GP-Hooks module to the new Elements module.

    Problem is, the GP-Hooks module link disappears from the dashboard as soon as “Elements” is activated. Which makes it kind of hard to copy over the code …

    #679493
    Leo
    Staff
    Customer Support

    You can still access legacy hooks module by clicking the Legacy Hooks button on the Elements listing page.

    Once it’s empty in there the button will disappear.

    Let me know if this helps πŸ™‚

    #679500
    Edin

    Perfect! Thank you!

    #679529
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.