Googlyzer – Display Google Analytics in WordPress

Embed Google Analytics in WordPress

Googlyzer Pro includes shortcodes that enable embedding of charts with real-time data from Google Analytics. Displaying data from Google Analytics in WordPress can be a powerful visual tool to allow web site managers and their users to see the impact of their content. Embedded charts can use page-level data, or site-wide data, can be based on a wide number of metrics and can be produced for any desired date range (assuming there is data available). Examples follow.

Example 1 – Displaying Total Number of Site Visitors Over Last 30 Days

[googlyzerSparkline title='Site Visitors Last 30 Days' metrics=ga:visitors linecolor=orange fillbackground=true]

[googlyzerSparkline title='Site Visitors Last 30 Days' metrics=ga:visitors linecolor=orange fillbackground=true]

Example 2 – Displaying Total Site Pageviews Over Last 6 Months

[googlyzerSparkline title='Site Pageviews in Last 6 Months' linecolor=red minspotcolor=yellow maxspotcolor=green spotcolor=blue start=2011-08-02 end=2012-02-09]

[googlyzerSparkline title='Site Pageviews in Last 6 Months' linecolor=red minspotcolor=yellow maxspotcolor=green spotcolor=blue start=2011-08-02 end=2012-02-09]

Example 3 – Displaying Total Visitors to This Page in Last 6 Months

[googlyzerSparkline title='Page Visitors in Last 30 Days' scope=Page metrics=ga:visitors linecolor=blue fillbackground=true height=100 width=300]

[googlyzerSparkline title='Page Visitors in Last 30 Days' scope=Page metrics=ga:visitors linecolor=blue fillbackground=true height=100 width=300]

Example 4 – Displaying Total Pageviews for This Page

[googlyzerSparkline title='Total Pageviews' scope=Page linecolor=green fillbackground=true height=100 width=300 start=2005-01-01]

[googlyzerSparkline title='Total Pageviews' scope=Page linecolor=green fillbackground=true height=100 width=300 start=2005-01-01]

Supported Shortcode Tags

  • dimensions – Google Analytics dimensions. Only single value supported in this version. Must be prefixed by ‘ga:’ according to standard Google Analytics format. Incorrectly formatted input will be converted to default. Default is ga:date.
    Example:
    dimensions=ga:date
  • end – End date for date range. Must be in YYYY-MM-DD format. Default is current date.
    Example:
    end=2011-12-31
  • fillbackground – Toggle for filling chart area beneath sparkline. Must be a boolean value (true/false). Default is false.
    Example:
    fillbackground=false
  • fillcolor – Background fill color. Ignored unless fillbackground=true. Can be entered as hex value or by web color name. Default is #ADFAFF (light blue).
    Example 1:
    fillcolor=#ADFAFF

    Example 2:

    fillcolor=green
  • height – Height in pixels for sparkline chart. Can be entered as integer only, or with ‘px’ suffix. Default is 75px.
    Example:
    height=75px
  • linecolor – Sparkline color. Can be entered as hex value or by web color name. Default is #FF0000.
    Example 1:
    linecolor=#FF0000

    Example 2:

    linecolor=blue
  • max_results – Maximum number of data values to be returned from Google Analytics. Default is 1000.
    Example:
    max_results=5000
  • maxspotcolor – Maximum data point marker color. Can be entered as hex value or by web color name, set to false to disable. Default is false.
    Example 1:
    maxspotcolor=yellow

    Example 2:

    maxspotcolor=false
  • minspotcolor – Minimum data point marker color. Can be entered as hex value or by web color name, set to false to disable. Default is false.
    Example 1:
    minspotcolor=red

    Example 2:

    minspotcolor=false
  • spotcolor – Last value data point marker color. Can be entered as hex value or by web color name, set to false to disable. Default is false.
    Example 1:
    spotcolor=orange

    Example 2:

    spotcolor=false
  • metrics – Google Analytics metrics. Only single value supported in this version. Must be prefixed by ‘ga:’ according to standard Google Analytics format. Incorrectly formatted input will be converted to default. Default is ga:pageviews.
    Example:
    metrics=ga:pageviews
  • scope – Scope of data to be collected from Google Analytics. Two possible options: ‘Site’ or ‘Page’. Default is Site.
    Example:
    scope=Page
  • sort – Sort order for data retrieved from Google Analytics. Two possible options: ‘ascending’ or ‘descending’. Default is ‘ascending’.
    Example:
    sort=descending
  • sort_column – Sort column for data retrieved from Google Analytics. Can be any metric or dimension included in data request. Default is ga:date.
    Example:
    sort_column=ga:date
  • start – Start date for date range. Must be in YYYY-MM-DD format. Default is 30 days prior to current date.
    Example:
    start=2011-06-30
  • title – Title for sparkline chart.
    Example:
    title="My Chart Title" Default is blank.
  • width – Width in pixels for sparkline chart. Can be entered as integer only, or with ‘px’ suffix. Default is 250px.
    Example:
    width=250px

WP e-Commerce Shortcode – Add & Checkout Button

WP e-Commerce Shortcode: Add & Go Direct to Checkout Button for WP e-Commerce

While customizing WP e-Commerce recently, I needed to add a button that would add a specific product variation to a customer’s shopping cart and go direct to the checkout page. What I ended up doing was adding a custom WP e-Commerce Shortcode. It’s a simple function really. It creates a button that runs the custom function.

Brief instructions follow. NOTE: technically this is a WP e-Commerce hack, and will be overwritten during upgrades of WP e-Commerce. In order to preserve it, the code below will need to be re-added to the WP e-Commerce shortcodes PHP file following an upgrade.

  1. Make a backup copy of
    ../wordpress/wp-content/plugins/wp-e-commerce/wpsc-includes/shortcode.functions.php
  2. At the bottom of the WP e-Commerce shortcodes PHP file –
    ../wordpress/wp-content/plugins/wp-e-commerce/wpsc-includes/shortcode.functions.php

    Add the code listed below, without removing or editing the existing text in that file.

  3. Save and close the WP e-Commerce shortcodes PHP file.
  4. Go to Store->Settings->Presentation and click on Flush Theme Cache.
  5. Add the add_and_go_direct_to_cart shortcode to any page or post where you wish to use it.

Code to be added to the shortcode.functions.php file

/**
 * Custom shortcode function added to create a button that adds product to cart and takes customer directly to checkout page.
 */
function wpsc_add_and_go_direct_to_cart_shortcode( $atts ) {
	// extract parameters and substitute defaults if necessary
	extract( shortcode_atts( 
		array(
			'class' => '',
    			'id' => '0',
    			'name' => '',
    			'value' => 'Add to Cart'
    			),
		$atts ) 
		);
	// build form for button
	$output = array(
		"<form action='" . get_option( 'shopping_cart_url' ) . "' method='post'>n",
		"<input type='hidden' name='wpsc_ajax_action' value='add_to_cart'>n",
		"<input type='hidden' name='product_id' value='" . $id . "'>n",
		"<input type='submit' id='product__submit_button' class='" . $class . "' name='" . $name . "' value='" . $value . "'>n",
		"</form>n"
		);
	// return form for output
	return implode( "", $output );
}

add_shortcode( $tag = 'add_and_go_direct_to_cart', $func = 'wpsc_add_and_go_direct_to_cart_shortcode');

add_and_go_direct_to_cart Shortcode Syntax

[add_and_go_direct_to_cart class='my_button_class' id=1 name='buy_my_product' value='Buy My Product']

Where id = your WPSC product id, class = your CSS button class, and value = your desired button label.