0

I'm installing a Pinterest tracking code and need to hash a email using SHA-256.

From Pinterest Docs:

Enhanced Match may also be used with the img tag. However, partners that use the img tag will need to format and hash themselves. Specifically, will need to be lower-cased and have all whitespace removed. They will then need to be hashed using the SHA-256 algorithm.

The formatted and hashed should be added to every Pinterest tag img tag URL on your page using the "&pd[em]=" parameter. The em parameter should be added to both the base code and the event code img tags.

For example:

<noscript>
<img height="1" width="1" style="display:none;" alt=""
src="https://ct.pinterest.com/v3/?tid=<YOUR_TAG_ID>&event=<EVENT_NAME>&pd[em]=<hashed_email_address>&noscript=1" />
</noscript>

My code so far:

    <?php
        if (Mage::getSingleton('customer/session')->isLoggedIn()) { 
           $customer = Mage::getSingleton('customer/session')->getCustomer();
           $CustomerEmail = $customer->getEmail();
        }
    ?>


    <img height="1" width="1" style="display:none;" alt=""
  src="https://ct.pinterest.com/v3/?tid=<?php echo $id ?>&pd[em]=<?php echo $CustomerEmail ?>&noscript=1" />

It seems I read Magento has this built-in not sure. Thank you.

1 Answer 1

1

Nevermind I found the answer here: How to use sha256 in php5.3.0

My new code:

<?php 
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
   $customer = Mage::getSingleton('customer/session')->getCustomer();
   $CustomerEmail = $customer->getEmail();
}
$pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();
?>
<script>
!function(e){if(!window.pintrk){window.pintrk = function () {
window.pintrk.queue.push(Array.prototype.slice.call(arguments))};var
      n=window.pintrk;n.queue=[],n.version="3.0";var
      t=document.createElement("script");t.async=!0,t.src=e;var
      r=document.getElementsByTagName("script")[0];
      r.parentNode.insertBefore(t,r)}}("https://s.pinimg.com/ct/core.js");
pintrk('load', '<?php echo $id ?>', {em: '<?php echo $CustomerEmail ?>'});
pintrk('page');
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt=""
src="https://ct.pinterest.com/v3/?tid=<?php echo $id ?>&event=<?php echo $pageIdentifier ?>&pd[em]=<?php echo hash('sha256', $CustomerEmail); ?>=1" />
</noscript>

I'm getting good :)

1
  • Where did you put this code? In what file? Commented Aug 13, 2020 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.