Jump to content

Use AdWords remarketing code by modifying Google Analytics code


Recommended Posts

Hi folks,

 

I read here and there in the forum topics for integrating AdWords Remarketing Code. Of course, people are frustrated again. Ok, it seems that if you choose to use the code from AdWords and place it in the right place in the right file it will probably work.

 

But in this case I want to modify the Google Analytics code to use remarketing. Here it is what Google Help says about that:

 

To enable these features for Universal Analytics, insert the bold line into your existing tracking code between the'create' and 'send' commands, as seen in this example:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-XX', 'example.com');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>

To revert the change, simply remove the line ga('require', 'displayfeatures');

 

Well, I've tried to make the change in the file header.tpl located in .../modules/ganalytics/views/templates/hook but AdWords still doesn't recognize the change and still says "We haven't detected the Google Analytics remarketing functionality on your website".

 

My version of prestahop is 1.6.0.9.

 

Any suggestions?

 
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

NOTE! i havent testet this 

	public function hookProductFooter($params)
	{
		$controller_name = Tools::getValue('controller');
		if ($controller_name == 'product')
		{
			// Add product view
			$ga_product = $this->wrapProduct((array)$params['product'], null, 0, true);
			$js = 'MBG.addProductDetailView('.Tools::jsonEncode($ga_product).');';

			// Michael Hjulskov
			$js .= 'ga(\'set\', \'dimension1\', \''.$ga_product['id'].'\');';
			// END Michael Hjulskov

			if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) > 0)
				$js .= $this->addProductClickByHttpReferal(array($ga_product));

			$this->js_state = 1;
			return $this->_runJs($js);
		}
	}

	private function _getGoogleAnalyticsTag($back_office = false)
	{
			/* Michael Hjulskov added a line -> ga(\'require\', \'displayfeatures\');
			return '
			<script type="text/javascript">
				(window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\');
				(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
				(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
				m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
				})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');
				ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\');
				ga(\'require\', \'ec\');
				'.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '').'
			</script>';
			*/
			return '
			<script type="text/javascript">
				(window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\');
				(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
				(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
				m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
				})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');
				ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\');
				ga(\'require\', \'displayfeatures\');
				ga(\'require\', \'ec\');
				'.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '').'
			</script>';
			// END Michael Hjulskov
	}
	public function addProductImpression($products)
	{
		if (!is_array($products))
			return;

		$js = '';
		foreach ($products as $product)
			$js .= 'MBG.add('.Tools::jsonEncode($product).",'',true);";

		// Michael Hjulskov
		$js_id_products_list = array();
		foreach ($products as $product)
			$js_id_products_list[] = $product['id'];
		if ($js_id_products_list)
			$js .= 'ga(\'set\', \'dimension2\', \''.implode(',', $js_id_products_list).'\');';
		// END Michael Hjulskov

		return $js;
	}

Edited by michaelhjulskov (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...