Drupal 6

Reporting Ubercart Orders to Google Analytics

Ubercart 2.x comes with a module that allows you to report completed orders to Google Analytics. The data reported is very useful there, where sales information may be combined with traffic reports and customizable goals to gauge the effectiveness of your web marketing and inform your future marketing efforts.

Getting Ubercart to report orders requires installation and configuration of the Google Analytics module using your account information and site ID. Once that is working properly, you simply need to install the Google Analytics for Ubercart module found in the Ubercart - extra category on your module installation page.

The module will then automatically inject the necessary Javascript on the standard checkout completion page to report the general transaction and item information to Google Analytics. If you need to alter the information sent at all, you can use a pair of simple alter hooks as necessary: hook_ucga_trans_alter() to alter the header information for the transaction and hook_ucga_item_alter() to alter the information sent about an individual product on the order.

There are plenty of payment modules out there, though, and not all of them end up at the default checkout completion page that the UC Google Analytics module is looking for. This is primarily a problem for modules that integrate payment services requiring redirection away from Ubercart to collect payment information. As a result, we made the function that governs the addition of the Javascript to the page extensible via hook_ucga_display().

Ryan's picture
Ryan Szrama

Ryan got his start in web development through an online sales company based in Louisville, KY, his home of over 10 years. It was there that he nursed Ubercart through its infancy to its use on over 20,000 websites as the Project Lead and community face of the project. Ryan joined Commerce Guys in 2009 and continued to lead Ubercart until branching out into Drupal Commerce, a new initiative focusing on empowering users to build e-commerce sites with the best new features that Drupal 7 has to offer. He focuses most of his time developing the code base, growing the community of contributors to the project, and training new users online and at community events.

10 Tips for E-commerce on Drupal

I wrote this article for a general web development blog, but it ended up not being published. It constitutes a simple checklist of tips and reminders for people building e-commerce websites on Drupal that I hope can still be useful published here. Feel free to contact us if you'd like to use the information / article in the attached PDF elsewhere.

  1. Know your tools.

    

Drupal is notorious for its abundance of modules written to address thousands of minor and major features.  E-commerce on Drupal is no exception, and the tool you use depends on your business needs and timeline.  Sites launching in the near future will be using Drupal 6 and have two e-commerce systems to choose from:

    

Ubercart - This is a full fledged e-commerce system designed to "just work" out of the box.  It offers the standard shopping cart features, integration with several payment and shipping quote services, and the ability to automate your order workflow without writing any code.  Additional features can be added by dozens of related contributed modules, and with over 18,000 live sites and hundreds of users and contributors, you're bound to find support for the functionality you need.

    

e-Commerce - The most recent version is a trimmed down e-commerce API that defines the components you'll use to build the e-commerce functionality you need.  The pool of contributors and users is relatively small compared to Ubercart, so you should feel comfortable doing some heavy lifting on your own and possible Drupal module development if you go this route.

    

For future sites targeting the upcoming Drupal 7, users should keep an eye on the Drupal Commerce project.  Spearheaded by the former project lead of Ubercart, the project is joining the attention to detail of the e-Commerce API and the attention to usability of Ubercart with the latest and greatest features of Drupal 7.  Drupal Commerce got some stage time at DrupalCon San Francisco and the CMS Expo and has attracted the attention of some of the top contributors to Drupal 7 with expertise in core API development, usability, and security.


Read more...

Ryan's picture
Ryan Szrama

Ryan got his start in web development through an online sales company based in Louisville, KY, his home of over 10 years. It was there that he nursed Ubercart through its infancy to its use on over 20,000 websites as the Project Lead and community face of the project. Ryan joined Commerce Guys in 2009 and continued to lead Ubercart until branching out into Drupal Commerce, a new initiative focusing on empowering users to build e-commerce sites with the best new features that Drupal 7 has to offer. He focuses most of his time developing the code base, growing the community of contributors to the project, and training new users online and at community events.

Ubercart Taxonomy Catalog

There are many ways to build a product catalog with Ubercart. We have used almost every method possible, Ubercart Catalog, Views, and even Apache Solr. I want to show what we think is a great alternative to the Ubercart Catalog and Views catalog. This will not get you the performance and facets that an Apache Solr catalog will get you. We will leave that for another post.

I refer to this method I am going to show you as the Ubercart Taxonomy Catalog.

The Ubercart Catalog module had some great features and configuration options our of the box, however customizing it it sometimes where most people see the wall at the end of the road. People often then try and replicate the catalog module in views which is a great start but leaves a big gap in terms of SEO and user friendliness.

The problem comes from the general concept of having duplicate content between your product catalog and the taxonomy pages. Also when a user clicks on a term on a product page they are directed to the taxonomy page rather that the product catalog for that term.

The best thing we could do is to make the taxonomy pages the actual product catalog. This reduces duplicate content and solves the problem of user clicking on the taxonomy terms and being thrown into the ugly river of product teasers.

Let me walk you through the painless process.

Step 1 - Setup your taxonomy structure the way you want it.

Don’t limit yourself to one vocabulary here. We suggest product type, manufacturer, and any other major divisions in your products. We suggest multi select where it makes sense, stay away from the required and tag options for this catalog use case.

Step 2 - Create your taxonomy term header view.

For my example I am using a simple table with the term image and term description. You will need the term image module installed for this wo work. This is Views import code.

$view = new view;
$view->name = 'taxonomy_term_header';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'term_data';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'tid' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'imagecache_preset' => 'product_list',
    'link_to_taxonomy' => 0,
    'exclude' => 0,
    'id' => 'tid',
    'table' => 'term_image',
    'field' => 'tid',
    'relationship' => 'none',
  ),
  'description' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'description',
    'table' => 'term_data',
    'field' => 'description',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'tid',
    'table' => 'term_data',
    'field' => 'tid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'product' => 0,
      'page' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '4' => 0,
      '2' => 0,
      '3' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'description' => 'description',
    'tid' => 'tid',
  ),
  'info' => array(
    'description' => array(
      'separator' => '',
    ),
    'tid' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));

Step 3 - Create your product grid view.

For this example I am creating a node view of products in a grid format.
This is Views import code.

$view = new view;
$view->name = 'product_grid_view';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'model' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'model',
    'table' => 'uc_products',
    'field' => 'model',
    'relationship' => 'none',
  ),
  'sell_price' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'sell_price',
    'table' => 'uc_products',
    'field' => 'sell_price',
    'relationship' => 'none',
  ),
  'addtocartlink' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'addtocartlink',
    'table' => 'uc_products',
    'field' => 'addtocartlink',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'product' => 0,
      'page' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '4' => 0,
      '2' => 0,
      '3' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'is_product' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'is_product',
    'table' => 'uc_products',
    'field' => 'is_product',
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 12);
$handler->override_option('style_plugin', 'grid');

Step 4 - Override the taxonomy page theme function

At the bottom of your themes template.php file add the following code.

function MYTHEME_taxonomy_term_page($tids, $result) {
$output = '';

// we use this view to render the content rather than normal taxonmy behaviour
$output .= views_embed_view('taxonomy_term_header', 'default', $tids[0]);
$output .= views_embed_view('product_grid_view', 'default', $tids[0]);

return $output;
}

Tim's picture
Tim Hill

Tim was the co-founder of Commerce Guys with Mike in 2008. Tim considers himself an EntreLeader by having the drive and motivation of an entrepreneur and the strength and vision of a leader, all rolled into one. Tim first got into e-commerce by working his way up in a large e-commerce company and then helping launch a new company selling retail products online. Tim has immersed himself into e-commerce on Drupal since 2006. Tim works within the company to manage the HR, travel and events, and accounting departments.

Understanding and Using Ubercart’s Payment API

Ubercart has a fairly straightforward API for processing and logging payments that is quite similar in both the 1.x and 2.x branches. As a developer, you may run into a situation where you need to make manual note of external payments or trigger the automatic processing of payments based on your business rules. In Ubercart, there is a difference between processing a payment with the function uc_payment_process() and just recording a payment with the function uc_payment_enter(). To explain the difference, you should first understand a few concepts related to the payment system in Ubercart and how payment data is displayed to customers and administrators. After covering the terms and concepts, a full description of both functions mentioned above will be given followed by a section on using the API to process credit card transactions in your own code.

Ryan's picture
Ryan Szrama

Ryan got his start in web development through an online sales company based in Louisville, KY, his home of over 10 years. It was there that he nursed Ubercart through its infancy to its use on over 20,000 websites as the Project Lead and community face of the project. Ryan joined Commerce Guys in 2009 and continued to lead Ubercart until branching out into Drupal Commerce, a new initiative focusing on empowering users to build e-commerce sites with the best new features that Drupal 7 has to offer. He focuses most of his time developing the code base, growing the community of contributors to the project, and training new users online and at community events.

Google Analytics with Ubercart

Place holder for upcoming article based on presentation.

Tim's picture
Tim Hill

Tim was the co-founder of Commerce Guys with Mike in 2008. Tim considers himself an EntreLeader by having the drive and motivation of an entrepreneur and the strength and vision of a leader, all rolled into one. Tim first got into e-commerce by working his way up in a large e-commerce company and then helping launch a new company selling retail products online. Tim has immersed himself into e-commerce on Drupal since 2006. Tim works within the company to manage the HR, travel and events, and accounting departments.

Add items to the cart with custom forms

The request for more robust Ubercart add to cart forms comes up fairly regularly. People generally have in mind the sort of form that allows customers to specify quantities for a set of products and add them to the cart all at once. The request came up so often that I put a short explanation on how to accomplish this through a custom form into an FAQ post on Ubercart.org.

This article will walk through a very basic example of how you can use the Ubercart function uc_cart_add_item() in a custom form submit handler to add multiple items to the cart at once. This article assumes a basic knowledge of Drupal's Forms API. Code examples are from Drupal 6, but they are mostly applicable to Drupal 5 as well.

Ryan's picture
Ryan Szrama

Ryan got his start in web development through an online sales company based in Louisville, KY, his home of over 10 years. It was there that he nursed Ubercart through its infancy to its use on over 20,000 websites as the Project Lead and community face of the project. Ryan joined Commerce Guys in 2009 and continued to lead Ubercart until branching out into Drupal Commerce, a new initiative focusing on empowering users to build e-commerce sites with the best new features that Drupal 7 has to offer. He focuses most of his time developing the code base, growing the community of contributors to the project, and training new users online and at community events.

Syndicate content