Site logo

Archived topic

Tracking Code on specific pages?

12 replies · Started by Edin on February 21, 2018

Viewing posts 1–13 of 13

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

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

Yup code looks good.

Nope it won't mess with the code without PHP :)

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

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)

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

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 ...

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 :)

Perfect! Thank you!

No problem :)

This archived topic is closed to new replies.