View a list of transactions in Google Analytics made when served by operator using Zopim (Zendesk Live Chat)

Sometimes you want to see the actual transactions in Google Analytics made during a session where the customer was served by a live chat operator (in this case Zopim – now called Zendesk live Chat).

To create a segment for each person called “Zopim – Served by “:

  • Create a new segment
  • Set conditions to include all sessions where Event Label =

Go to the “Conversions > Ecommerce > Transactions” report

Apply the above segment.

Set the date range (eg. last 30-days).

Google analytics transactions served by operators report

Shopify (not Plus) Google Tag Manager Checkout Page Data Layer

Intro

When using Shopify Standard (not plus) you add the Google Tag Manager snippets to your theme layout file in the head and body as per standard instructions, and then you need to add some code and setup for tracking conversions from the order page. Follow these steps:

Add this code to checkout scripts

Go to Settings > Checkout > Scripts

{% if first_time_accessed %}

<script>

var lftOrders = {{ customer.orders.size }};
var custType = 'repeatcustomer';
if (lftOrders == 1)
{
 custType = 'newcustomer';
}

var coupons = 'None';  
{% assign lcoupons = "" %} 
{% for discount in order.discounts %}  
 {% assign lcoupons = lcoupons | append:  discount.code | upcase   %}
{% endfor %}

var dataLayer = window.dataLayer = window.dataLayer || [];
dataLayer.push(
{
 'ecommerce' : {
  'purchase': {
   'actionField': {
   'id': '{{order.order_number}}',
   'revenue': {{total_price | times: 0.01}},
   'subtotal': {{subtotal_price | times: 0.01}},
   'tax': {{tax_price | times: 0.01}},
   'shipping': {{shipping_price | times: 0.01}},
   'customerType': custType,
   'lifetimeOrders': lftOrders,
   'email': '{{order.email}}',
   'coupon': '{{ lcoupons }}'
  },
  'products': [
  {% for line_item in line_items %}
   {
    'id': '{{line_item.sku}}',
    'name': '{{line_item.vendor | append: ' - '  | append: line_item.product.title}}',
    'category': '{{line_item.product.type}}',
    'brand': '{{line_item.vendor}}',
    'price': {{line_item.line_price | times: 0.01}},
    'quantity': {{line_item.quantity}}
   },
  {% endfor %}]
  }
 }
}
);
</script> 

<!-- enter the google tag manager head and body code here //-->

{% endif %} 

Define some variables in Google Tag Manager

  • Create a new constant user defined variable called gaAccountId with value = YOURGAACCOUNTID.
  • Create a new constant user defined variable called gaCrossDomains with value = “mywebsite.com,checkout.shopify.com”
  • Create a new constant user defined variable called gaDomain with value = “auto”
  • Optionally create variables based on the data layer. For example:
    • Create a Data Layer Variable for OrderID named transOrderID with value ecommerce.purchase.actionField.id
    • Create Data Layer Variables for Revenue, Shipping, Tax, Coupon, SubTotal, Email, CustomerType. eg transRevenue with value ecommerce.purchase.actionField.revenue
  • Create a page view trigger named “Transaction” with 2 conditions:
    • Page url matches RegEx(ignore case) https://checkout.shopify.com/(.*)/orders/(.*)thank(.*)
    • Referrer does not contain myshopify.com/admin/orders/

Create Google Analytics tag (type = Universal Analytics)

  • Tracking ID : {{gaAccountID}} – This is the variable we created where we stored our TrackingID
  • allowLinker: true
  • cookieDomain: {gaDomain}}
  • Enable Enhanced Ecommerce Features – Check
  • Use data layer – Check
  • Enable Display Advertising Features – Check
  • Auto Link Domains: {{gaCrossDomains}}
  • Use Hash as Delimiter: False
  • Decorate Forms: False
  • Under Triggering
    • Select All pages
    • Select Add Exception, and select Transaction.

Create Google Analytics Transaction Tag

  • Copy the tag we created above
  • Remove all the triggers and excepts
  • Select the trigger to the Transaction trigger we initially created.

References:

  • https://help.shopify.com/manual/reports-and-analytics/google-analytics/google-tag-manager
  • https://www.dbmarketer.com/db-marketer/google-tag-manager-on-shopify/
  • https://github.com/toddheslin/gtm-ecommerce-platforms/blob/master/shopify/shopify.md

Mailchimp iCal Link

To get your list URL:

Click on Lists > list > Sign-up forms

Click on your sign up form url to open it in a new window

The url will be something like this:

http://<ACCOUNT_NAME>.usX.list-manage.com/subscribe?u=<USER_ID>&id=<LIST_ID>

Get those details and add the following link calendar by URL

http://<ACCOUNT_NAME>.usX.list-manage.com/ical?u=<USER_ID>&id=<LIST_ID>

Sneak Peek: Mailchimp ABANDONED_CART merge tags for custom HTML email

You can use ABANDONED_CART blocks similar to PRODUCT_RECOMMENDATIONS

For example, you can display a list of items in the cart:

*|ABANDONED_CART:[$total=3]|*
<a href="*|CART:URL|*">
<img src="*|PRODUCT:IMAGE_URL|*" />
<br />*|PRODUCT:TITLE|*
<br />*|PRODUCT:PRICE|*
</a>
*|END:ABANDONED_CART|*

Or create a button:

*|ABANDONED_CART:[$total=1]|*
<a href="*|CART:URL|*">Complete your order</a>
*|END:ABANDONED_CART|*

Custom Addthis Social Media Sharing Buttons for Shopify (for free)

The process is:

  1. Create a Google Analtyics account and get your site ID
  2. Sign-up to Addthis and get your profile ID
  3. Sign-up to Bitly for URL shortening on Tweets (and get your API username and key)
  4. Add the Shopify Theme settings to your settings_schema.js
  5. Add the javascript to your Shopify theme layout file
  6. Add HTML for sharing buttons to your Shopify pages
  7. Add custom icon font and CSS to style your buttons
  8. Configure the Addthis Custom HTML Email Template
  9. Create a Facebook App and add the id to the settings

Addthis theme settings

Add this code to your Shopify settings_schema.json then click on “customise theme” to enter the right values.

  {
    "name": "Addthis Sharing Settings",
    "settings": [
      {
        "type": "checkbox",
        "id": "addthis_use",
        "label": "Use Addthis?"
      },
      {
        "type": "text",
        "id": "addthis_id",
        "label": "AddThis ID"
      },
      {
        "type": "text",
        "id": "google_analytics_id",
        "label": "Google Analytics ID"
      },
      {
        "type": "text",
        "id": "addthis_twitter_id",
        "label": "Twitter name"
      },
      {
        "type": "text",
        "id": "addthis_twitter_string",
        "label": "Twitter string",
        "default": "*title* Coming Soon. #signup #exclusiveaccess"
      },
      {
        "type": "checkbox",
        "id": "addthis_bitly_use",
        "label": "Use Bitly?"
      },
      {
        "type": "checkbox",
        "id": "addthis_email_template_use",
        "label": "Use custom email template?"
      },
      {
        "type": "text",
        "id": "addthis_email_template_name",
        "label": "Add this email template name",
        "default": "product_template"
      },
      {
        "type": "text",
        "id": "addthis_facebook_app_id",
        "label": "Facebook App ID"
      },
      {
        "type": "text",
        "id": "addthis_facebook_redirect_url",
        "label": "Facebook Redirect URL"
      }
    ]
  }

Addthis Javascript

Create a new snippet called “addthis.liquid” and add it to the end of your theme (before end of body tags) using {% include ‘addthis’ %}

{% if settings.addthis_use %}
<script>
  jQuery(function($) {
    initAddThis();
    jQuery('.sharenulify').on('click', function (e) {
      return false;
    });
  });
  function initAddThis() 
  {
    if ( typeof( window[ 'addthis' ] ) != "undefined" ) {
      addthis.init()
    } 
  }
</script> 

{% capture addthis_title %}{% endcapture %}
{% capture addthis_description %}{% endcapture %}
{% capture addthis_image %}{% endcapture %}
{% if template contains 'product' %}
  {% capture addthis_title %}{{ product.title | strip_html | escape }}{% endcapture %}
  {% capture addthis_description %}{{ product.description | strip_html | strip_newlines | truncatewords: 30, '' | escape }}{% endcapture %}
  {% capture addthis_image %}https:{{ product.featured_image | img_url: 'large' }}{% endcapture %}
{% elsif template contains 'article' %}
  {% capture addthis_title %}{{ article.title | strip_html | escape }}{% endcapture %}
  {% capture addthis_description %}{{ article.excerpt_or_content | strip_html | strip_newlines | truncatewords: 30, '' | escape }}{% endcapture %}
  {% if article.image %}
    {% capture addthis_image %}https:{{ article.image.src | img_url: 'large' }}{% endcapture %}
  {% endif %}
{% elsif template contains 'page' %}
  {% capture addthis_title %}{{ page.title | strip_html | escape }}{% endcapture %}
  {% capture addthis_description %}{{ page.content | strip_html | strip_newlines | truncatewords: 30, '' | escape }}{% endcapture %}
  {% assign img_tag = '<' | append: 'img' %}
  {% if page.content contains img_tag %}
    {% assign src = page.content | split: 'src="' %}
    {% assign src = src[1] | split: '"' | first | remove: 'https:' | remove: 'http:' | replace: '_small.', '_large.' %}
    {% capture addthis_image %}https:{{ src }}{% endcapture %}
  {% endif %}
{% else %}
  {% capture addthis_title %}{{ page_title | escape }}{% endcapture %}
  {% if page_description %}{% capture addthis_description %}{{ page_description | escape }}{% endcapture %}{% endif %}
{% endif %}

{% capture addthis_twitter_string_calculated %}{{ settings.addthis_twitter_string | replace: '*title*', addthis_title }}{% endcapture %}  
<script type="text/javascript">
  var addthis_config = {
    {% if settings.google_analytics_id.size > 0 %}
    data_ga_property: '{{ settings.google_analytics_id }}',
    data_ga_social : true,
    {% endif %}
    "data_track_addressbar":false,
    ui_use_css : true,
    image_include: "at_include",
    image_exclude: "at_exclude"
  };
  addthis_share = {
    {% if settings.addthis_bitly_use %}
    url_transforms : {
      shorten: {
        twitter: 'bitly',
        facebook: 'bitly'
      }
    }, 
    shorteners : {
      bitly : {} 
    },
    {% endif %}
    url: "{{ canonical_url }}",
    title: "{{ addthis_title }}",
    description: "{{ addthis_description }}",
    passthrough : {
      twitter: {
        {% if settings.addthis_twitter_id.size > 0 %}via: "{{ settings.addthis_twitter_id }}",{% endif %}
        text: "{{ addthis_twitter_string_calculated }}"
      }{% if settings.addthis_facebook_app_id.size > 0 %},
      facebook: {
        app_id: '{{ settings.addthis_facebook_app_id }}',
        redirect_uri: '{{ settings.addthis_facebook_redirect_url }}',
      }{% endif %}
    }
    {% if settings.addthis_email_template_use and addthis_image.size > 0 %},
    email_template: "{{ settings.addthis_email_template_name }}",
    email_vars: { 
      thisTitle: "{{ addthis_title }}" ,
      thisDescription: "{{ addthis_description }}", 
      thisImage: "{{ addthis_image }}" ,
    }
    {% endif %}
  }
</script>        
<script type="text/javascript" src="https://s7.addthis.com/js/300/addthis_widget.js#pubid={{ settings.addthis_id }}" async="async"></script>
{% endif %}

HTML for share buttons

Create a new snippet called “addthis-share-buttons.liquid” and add it on any page you like using {% include ‘addthis-share-buttons’ %}

<div class="product-share">
  <a class="product-share-button" href="#">Share</a>
  <div class="share">
    <ul>
      <li><a class="tooltip sharebutton addthis_button_facebook" id="share_facebook" title="Share {{ mysharetitle }} on Facebook"><i class="fa fa-facebook"></i></a></li>
      <li><a class="tooltip sharebutton addthis_button_twitter" id="share_twitter" title="Share {{ mysharetitle }} on Twitter"><i class="fa fa-twitter"></i></a></li>
      <li><a class="tooltip sharebutton addthis_button_tumblr" id="share_tumblr" title="Share {{ mysharetitle }} on Tumblr"><i class="fa fa-tumblr"></i></a></li>
      <li><a class="tooltip sharebutton sharenulify addthis_button_pinterest_share" id="share_pinterest" title="Share {{ mysharetitle }} on Pinterest"><i class="fa fa-pinterest"></i></a></li>
      <li><a class="tooltip sharebutton addthis_button_email" id="share_email" title="Send  {{ mysharetitle }} to a friend by Email"><i class="fa fa-envelope-o"></i></a></li>
      <li><a class="tooltip sharebutton addthis_button_compact" id="share_other" title="More share options"><i class="fa fa-bookmark"></i></a></li>
    </ul>
  </div>
</div>

Use CSS to style your buttons

For Fontawesome icons, remember to add the font css to your theme file.

.product-share-button, .share { display:inline-block; }
.share ul { display:inline-block; list-style:none; margin:0; padding:0; }
.share li {  margin:0; padding:0; display:inline-block; }
.share li a { display:inline-block; margin:0; padding:10px; font-size:18px; line-height: 38px;}

Google Analytics Exclude URL Query Parameters

A list of url query parameters to exclude from Google Analytics for various e-commerce apps

Shopify

  • q
  • bis_id
  • checkout_url
  • variant
  • contact_posted
  • cache
  • preview_key

Shopify app “Back in Stock Alerts”

  • bis_id

Magento

  • siteID
  • SiteID
  • SID
  • sid
  • ___SID
  • cat
  • limit
  • sort_by

Mailchimp

  • u
  • id
  • e
  • mc_id
  • mcid
  • goal

Mailchimp field validation test routine (for the country field)

Set up a mailchimp account and get an API key.

Download the mailchimp api for php.

Create a new list in mailchimp, and add a drop-down field with merge tag ‘COOUNTRY’ and enter in your preferred values.

Then do this to test a string against those values:

// required files and config variables
require_once 'mailchimp-api-class/inc/MCAPI.class.php';
require_once 'mailchimp-api-class/inc/config.inc.php'; 

// connect with mailchimp
$api = new MCAPI($apikey);

// get the list of valid countries
$country_choices = get_country_choices($api, $listId);

// create a list of strings to test
$countries = array(
				   'australia',
				   'Australia',
				   'aus',
				   'New Zealand',
				   'United States',
				   'USA',
				   );

// output test result
foreach ($countries as $country)
{
	echo $country." is ";
	echo (validate_country($country, $country_choices)) ? "GOOD" : "BAD";
	echo "<br />";
}


// a function to check if the country exists in an array
function validate_country($str, $country_choices)
{
	return in_array ( $str, $country_choices );
}

// a function to get only the country names into a single array
function get_country_choices($api, $listId)
{
	$country_choices = array();
	$merge_tags = $api->listMergeVars($listId);
	if ($api->errorCode){
		return false;
	} else {
		
		if (is_array($merge_tags) && count($merge_tags) > 0)
		{
			foreach ($merge_tags as $mtag)
			{
				if ($mtag['tag'] == "COUNTRY")
				{
					$country_choices = $mtag['choices'];
				}
			}
		}
		return $country_choices;
	}
}