Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass the current view name into my Google Analytics element?
    text
    copied!<p>I am setting up GA within a Cake multi-page ordering process. One requirement is, that the "_trackPageview" push should include a variable representing custom URL paths, depending on the current step of the process (i.e. <code>_gaq.push(['_trackPageview', '/dsl/shop/availability/$url_addendum']);</code>.</p> <p>I did set up the GA JS snippet as a Cake element google_analytics.ctp:</p> <pre><code>&lt;?php $gaCode = Configure::read('xxx.ga.tracking_code'); if (!isset($url_addendum)) $url_addendum = ''; if ($gaCode) { $googleAnalytics = &lt;&lt;&lt;EOD &lt;script type="text/javascript"&gt; var _gaq = _gaq || []; _gaq.push(['_setAccount', '$gaCode']); _gaq.push(['_trackPageview', '/xxx/shop/availability/$url_addendum']); _gaq.push(['_gat._anonymizeIp']); _gaq.push(['_setDomainName', 'xxx']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); &lt;/script&gt; EOD; echo $googleAnalytics; } ?&gt; </code></pre> <p>The order process is displayed utilizing a layout shop.ctp in which I added <code>echo $this-&gt;element('google_analytics');</code> into the header section. This is working fine of course.</p> <p>My problem now is, that I'd need to trigger _trackPageView with my custom $url_addendum parameter, seperately per view/step of the order process. But without producing duplicates of the page view and without calling the whole GA-element within the body of each view.</p> <p>So I guess the question is: Is there a way to leave the GA-element call in the head of the layout (where it should be naturally, imho) and call custom _trackPageviews without having to use _trackEvent instead ?</p> <p>Is there a way to pass the view name up to the layout in order to evoke a fitting call in the form of <code>echo $this-&gt;element('google_analytics', array('url_addendum' =&gt; 'currentview'));</code> ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload