Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2013
    Posts
    25
    Plugin Contributions
    0

    Default Tracking products added to basket in google analytics / event tracking

    Hi,

    I´d like to track products that have been added to basket.

    As decribed here http://www.blog.analyticsinspector.c...gle-analytics/ I have to add event tracking code to my "add to cart" - button.

    In html_output.php I added the code
    PHP Code:
    // form input button
       
    $css_button '<input class="' $mouse_out_class '" ' $css_button_js ' type="submit" value="' .$text '"' $parameters $style ' onclick="_gaq.push([\'_trackEvent\', \'addtobasket\', \'Product name\', \'Tracker Button\']);" />';
        } 
    So my html-output is
    HTML Code:
    <!--bof Add to Cart Box -->
                      <div id="cartAdd">
        Anzahl: <input type="text" name="cart_quantity" value="1" maxlength="6" size="4" /><br /><br />
    <input type="hidden" name="products_id" value="944" />
    <input class="cssButton button_in_cart" onmouseover="this.className='cssButtonHover button_in_cart button_in_cartHover'" onmouseout="this.className='cssButton button_in_cart'" type="submit" value="In den Warenkorb " style="width: 110px;" onclick="_gaq.push(['_trackEvent', 'addtobasket', 'Product name', 'Tracker Button']);" />        
     </div>
      <!--eof Add to Cart Box-->
    But in analytics my conversion-goal is alway 0.
    My goal:
    category (Equals to) =addtobasket
    Action (Equals to) =Product Name
    Label (Equals to) = Tracker Button

    Any idea what might have gone wrong?

    Best ragards
    Dave

  2. #2
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Tracking products added to basket in google analytics / event tracking

    Have you tried adding "javascript:" to the start of the onclick action?
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  3. #3
    Join Date
    Sep 2013
    Posts
    25
    Plugin Contributions
    0

    Default Re: Tracking products added to basket in google analytics / event tracking

    No, I havent.

    But I am not sure what have in mind ... how would the code look like?

  4. #4
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Tracking products added to basket in google analytics / event tracking

    Nevermind on the "javascript:", it is not needed... I do know the Google Analytics code needs to be loaded and using _gaq before the link is clicked on... I typically use jQuery to attach GA tracking to links and submit actions... Can say it works that way. Can also tell you events do not always show up right away in Google Analytics, sometimes they take 24-48 hours.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  5. #5
    Join Date
    Sep 2013
    Posts
    25
    Plugin Contributions
    0

    Default Re: Tracking products added to basket in google analytics / event tracking

    Thanks for your help.

    Can you pls. tell me the code I should use with jQuery to load and use _gaq?

  6. #6
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Tracking products added to basket in google analytics / event tracking

    Keep in mind these examples REQUIRE the following (for the web page):
    1. jQuery library loaded.
    2. Google Analytics "ga.js" asynchronous code loaded.
    3. Google Analtyics configured for tracking your domain.
    4. Google Analtyics snippet uses _gaq (not a different variable).

    These NEED to occur before any "submit" or "click". There is still a small chance the event will not be tracked.

    You will ALSO want to look into adding Google Analytics "e-commerce tracking" when a transaction is completed. There are a few threads on this website and the internet with examples :)

    EXAMPLE - track "all" form submits (not just successful ones). Yes this should be attached to the "form" not the "input".
    Code:
    $(document).ready(function() {
      $('form').submit(function(event) {
        
        // Add some code to determine which product is added
        var product = 'Product Name + ID';
    
        var _gaq = _gaq || []; // Left to avoid issues if GA not loaded
        _gaq.push(['_trackEvent', 'addtobasket', 'product added', product]);
      });
     });
    EXAMPLE - track clicks sending visitors to external resources (other websites such as social media):
    Code:
    jQuery(document).ready(function() {
      var re = new RegExp('^http(:?s)?://' + document.location.hostname);
      $('body').on('click', 'a', (function() {
        var href = $(this).attr('href');
        if(!re.test(href)) {
          var _gaq = _gaq || []; // Left to avoid issues if GA not loaded
          _gaq.push(['_trackEvent', 'external', 'link', href]);
        }
      }));
    });
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  7. #7
    Join Date
    Sep 2013
    Posts
    25
    Plugin Contributions
    0

    Default Re: Tracking products added to basket in google analytics / event tracking

    Hi lhungil,

    thanks for your support.

    I am a beginner in GA and zencart, so I am not sure what you mean.

    1-4 should be ok because I can track visitors on the webside. e-commerce-tracking is also activated.

    "Yes this should be attached to the "form" not the "input"."

    Do you mean?
    PHP Code:
    // form input button
       
    $css_button '<input class="' $mouse_out_class '" ' $css_button_js ' type="submit" value="' .$text '"' $parameters $style .

       $(
    document).ready(function() {
      $(
    'form').submit(function(event) {

        
    // Add some code to determine which product is added
        
    var product 'Product Name + ID';

        var 
    _gaq _gaq || []; // Left to avoid issues if GA not loaded
        
    _gaq.push(['_trackEvent''addtobasket''product added'product]);
      });
     });

       
    " />';
        } 
    That seems not to work. Or do you mean anything else?

 

 

Similar Threads

  1. Replies: 22
    Last Post: 20 Sep 2021, 02:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR