Facebook PageView event ignore if anchor changes but url remains - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, March 25, 2023

Facebook PageView event ignore if anchor changes but url remains

so I'm currently loading to my page head the facebook pixel code and automatically sending a PageView event after its loaded but for some reason its tracking anchor changes when I would like to avoid this.

My website has a cart for example and when I open it as a side panel it adds a #cart to the url but the user didn't really change url and tracking anchor changes is just creating miss information in our statistics and I was wondering if there was a way to ignore anchor changes?

<!-- Meta Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
    <?php
    $dataProcessingOptionsCode = $block->getDataProcessingOptionsJSCode();
    if (strlen($dataProcessingOptionsCode) > 0) {
        echo $dataProcessingOptionsCode."\n";
    }
    ?>
fbq(
  'init',
  '<?= $block->getFacebookPixelID() ?>',
    <?= $block->getPixelInitCode() ?>,
  {agent: '<?= $block->getFacebookAgentVersion() ?>' }
);
fbq('track', 'PageView', {
  source: "<?= $block->getSource() ?>",
  pluginVersion: "<?= $block->getPluginVersion() ?>"
});
</script>


source https://stackoverflow.com/questions/75837045/facebook-pageview-event-ignore-if-anchor-changes-but-url-remains

No comments:

Post a Comment