Posted on 4 Comments

Fix Anaraky Google Dynamic Remarkting Tag extension

Magento Logo

By default, Anaraky Google Dynamic Remarkting Tag (“Anaraky GDRT”) does not set correct page type “other“, as described in Google’s Dynamic Remarketing guidelines. Instead, it uses “siteview“. To overcome this behavior there are only 2 simple modifications required.

Required modifications for Anaraky Gdrt extension

First, in

app/code/community/Anaraky/Gdrt/Block/Script.php on line 51 replace siteview by other:

$params = array('ecomm_pagetype' => 'siteview');

becomes

$params = array('ecomm_pagetype' => 'other');

Second, in the same file on line 104 replace

$params = array( 'ecomm_pagetype' => 'siteview' );

with

$params = array( 'ecomm_pagetype' => 'other' );

Hint on using Anaraky custom page setup

Furthermore, when using the custom page setup options make sure to omit the trailing slash when only specifying module/controller setup, e.g. checkout/cart as shown below:

Anaraky Gdrt Magento Extension

Anaraky Google Dynamic Remarkting Tag does string comparison check without the trailing slash in the observer class:

foreach ($gdrtPages as $k => $v) {
  $v = rtrim($v, '/');
  if ($mName . '/' . $cName . '/' . $aName == $v ||
    $mName . '/' . $cName == $v)
  {
    $pageType = $k;
  }
}

Handling special prices and grouped/bundle products for “ecomm_totalvalue”

In case you run into problem when displaying special prices or handling grouped or bundle products in the ecomm_totalvalue field here is a quick fix to add this check. Add the following function in Script.php:

private function _getProductPrice($product) {

 $totalvalue = 0;

 // check if we are handling grouped products
 if($product->getTypeId() == 'grouped') {
 $groupedSimpleProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

 $groupedPrices = array();

 foreach($groupedSimpleProducts as $gSimpleProduct) { 
 $groupedPrices[] = $this->_getProductPrice($gSimpleProduct);
 }

 $totalvalue = min($groupedPrices);

 } else { // handle other product types
 $_price = Mage::helper('tax')->getPrice($product, $product->getPrice(), $inclTax);
 $_specialPrice = Mage::helper('tax')->getPrice($product, $product->getSpecialPrice(), $inclTax);
 $_finalPrice = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), $inclTax);

 if($_price == $_finalPrice) { // no special price
 $totalvalue = (float)$_price;
 } else { // get special price
 if((float)$_finalPrice > 0 && (float)$_finalPrice <= (float)$_price) {
 $totalvalue = (float)$_finalPrice;
 } else {
 $totalvalue = (float)$_price;
 }
 }
 } 

 return $totalvalue;
 }

Second, change the “product” case like so:


case 'product':
$product = Mage::registry('current_product');

$totalvalue = $this->_getProductPrice($product);

$params = array(
'ecomm_prodid' => $this->getEcommProdid($product),
'ecomm_pagetype' => 'product',
'ecomm_totalvalue' => (float)number_format($totalvalue, '2', '.', '')
);
unset($product);
break;

Don’t forget to flush the cache afterwards.

Posted on Leave a comment

Resolving IPv6 issues with GMail using qmail smtp

Source Code Icon

In case you are running into problems with Google Mail (GMail) rejecting mail from your qmail server running on native IPv6 with the following message

2a00:1450:4013:0c01:0000:0000:0000:001a failed after I sent the message. Remote host said: 550-5.7.1 [xxx:xxx:xxx:xxx::x 12] Our system has detected that this 550-5.7.1 message is likely unsolicited mail. To reduce the amount of spam sent 550-5.7.1 to Gmail, this message has been blocked. Please visit 550-5.7.1 http://support.google.com/mail/bin/answer.py?hl=en&answer=188131 for 550 5.7.1 more information. e7si30051500wiy.79 – gsmtp

make sure that you double-check the following settings:

  1. MX record matches the hostname set in qmail, /var/qmail/control/me
  2. Reverse DNS record for your server IP, i.e. PTR record, for both IPv6 and IPv4
  3. SPF records are set properly and point to your MX records and server IP for both IPv6 and IPv4

Check MX record

First of all make sure that you MX records match the hostname set in the qmail configuration. You can check your MX settings using the MXToolbox.

Check Reverse DNS record – PTR record

Second, make sure that your IPv4 and especially IPv6 IPs have a PTR record that resolves to the MX entry set for your domain. You can check your Reverse DNS lookup using the MXToolbox.

Check SPF record

Finally, GMail (and probably other mail providers too) will check for correct SPF or DKIM records. Normally, the SPF record only is sufficient. Checkout the SPFWizard on how to assemble your IN TXT SPF record. Make sure to add entries for IPv6 too, e.g.

v=spf1 mx a ip4:xx.xx.xx.xx ip6:y:yyyy:yyy:yyy:yyyy::y include:mail.yourserver.com include:mail2.yourserver.com -all

Check SMTP

Finally, check your server setup by either sending out mail to GMail recipients or testing it with the excellent Allaboutspam e-mail tester. That should get qmail working with native IPv6 support and GMail.

Posted on Leave a comment

Retrieving value of hidden input DOM element in Google Tag Manager (GTM)

Google Logo

When implementing event tracking of user comments using Google Tag Manager for WordPress I came across a pretty strange behavior when trying to retrieve the value of a hidden <input> field holding the current comment post id (comment_post_ID) that should serve as event label for Google (Universal) Analytics.

WordPress Comment Form

Below you find the WordPress comment form used by most templates today. Pay attention to line 11 that shows the hidden input field comment_post_ID. This field’s value should be used as event label.

&lt;form id=&quot;commentform&quot; class=&quot;comment-form&quot; action=&quot;http://www.yourdomain.com/wp-comments-post.php&quot; method=&quot;post&quot; novalidate=&quot;&quot;&gt;
&lt;span id=&quot;email-notes&quot;&gt;Your email address will not be published.&lt;/span&gt; Required fields are marked &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; 
&lt;label for=&quot;author&quot;&gt;Name &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;&lt;/label&gt; 
&lt;input id=&quot;author&quot; name=&quot;author&quot; size=&quot;30&quot; type=&quot;text&quot; value=&quot;&quot; /&gt; 
&lt;label for=&quot;email&quot;&gt;Email &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;&lt;/label&gt; 
&lt;input id=&quot;email&quot; name=&quot;email&quot; size=&quot;30&quot; type=&quot;email&quot; value=&quot;&quot; /&gt; 
&lt;label for=&quot;url&quot;&gt;Website&lt;/label&gt; &lt;input id=&quot;url&quot; name=&quot;url&quot; size=&quot;30&quot; type=&quot;url&quot; value=&quot;&quot; /&gt; 
&lt;label for=&quot;comment&quot;&gt;Comment&lt;/label&gt; 
&lt;textarea id=&quot;comment&quot; cols=&quot;45&quot; name=&quot;comment&quot; rows=&quot;8&quot;&gt;&lt;/textarea&gt; 
&lt;input id=&quot;submit&quot; class=&quot;submit&quot; name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Send your comment&quot; /&gt; 
&lt;input id=&quot;comment_post_ID&quot; name=&quot;comment_post_ID&quot; type=&quot;hidden&quot; value=&quot;SOME_ID&quot; /&gt; 
&lt;input id=&quot;comment_parent&quot; name=&quot;comment_parent&quot; type=&quot;hidden&quot; value=&quot;0&quot; /&gt; 
&lt;input id=&quot;akismet_comment_nonce&quot; name=&quot;akismet_comment_nonce&quot; type=&quot;hidden&quot; value=&quot;SOME_HASH&quot; /&gt; 
&lt;input id=&quot;ak_js&quot; name=&quot;ak_js&quot; type=&quot;hidden&quot; value=&quot;SOME_HASH&quot; /&gt;
&lt;/form&gt;

Retrieve value using Google Tag Manager

Per definition, Google Tag Manager evaluates DOM element variables based on an Element ID and optionally on an Attribute value. In case no Attribute Name is specified the value attribute will be used by default:

If the attribute name is set, the variable’s value will be that of the DOM element attribute; otherwise, the variable’s value will be the text of the DOM element.

Unfortunately, this does not seem to (always) work for hidden input fields. Therefore, make sure to specify the Attribute Name value manually: Google Tag Manager DOM Element variable Although, you can also use Custom JavaScript variables to achieve the same DOM element variables are clearly the way to go here.

Posted on 1 Comment

PHP Mailing List – Version 2.0.0 Released

Today, version 2.0.0 of PHP Mailing List was released. Due to numerous inquiries support for Google Analytics tracking code was added. You can simple set it via the supplied config file. Also, protocol prefixes in the template files have been removed for auto-detection.

Feel free to download the latest version via GitHub.

UPDATE: In version 2.2.0 Google Analytics event tracking has been added.

Posted on Leave a comment

Multiple Google AdSense ad blocks on same page are causing error 400 Bad Response

Google Logo

When trying to include multiple Google AdSense ad blocks using the code provided by Google on the same page you will likely get a 400 Bad Response error.

This is caused by including adsbygoogle.js multiple times:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Thus, simply include adsbygoogle.js only once and use the ad generation code where applicable:

<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="XYZ"
     data-ad-slot="XYZ"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Hint: When using WordPress and custom themes you can simply add the required Adsense JS file adsbygoogle.js using the following code in your theme’s functions.php file:

function add_google_adsense_js() {
    wp_enqueue_script( 'google_adsense_js', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js');
}

add_action( 'wp_enqueue_scripts', 'add_google_adsense_js' );