Passing Shopify Custom Dimensions to Google Analytics

Highlighted
New Member
1 0 0

Hi there,

So I'm trying to setup the cutom dimensions in Google Analytics in order to create the remarketing lists. Everything is going more or less "alrighty" but I'm stuck in the last step: using variables so the values changes accordingly.

This is how I set it up in Shopify:

But the problem is that Shopify is not changing the values accordingly, here is a screenshot of the tag manager:

So I'm trying to find out how I can set/pass this variables from Shopify to Analytics.

Any hints?

Thanks!

0 Likes
Highlighted
New Member
8 0 0

I was able to use the instructions at https://www.tastyplacement.com/install-dynamic-remarketing-shopify

This seems to be working as I am collecting data and I can use it both in Google Analytics and in AdWords to create custom audiences.  Be aware it does take awhile before the data will begin to populate correctly in GA and AW.

The code I used is below and it needs to be placed in your theme.liquid file right before the /body tag. Liquid object calls do not work if placed into the "Additional Google Analytics Javascript" dialog box in the Shopify backend (which is a mystery to me!!!).  Make sure to alter the code below based on your specific GA custom dimensions and Shopify site.

 <!-- Begin Google Analytics Vertical Attributes -->
<script type="text/javascript">
ga('set','dimension1', 'shopify_US_{{product.id}}_{{product.variants.first.id}}');
ga('set','dimension2', '{{product.price_min|money_without_currency}}');
ga('set','dimension3', '{{template}}');
</script>

 

0 Likes
Highlighted
New Member
2 0 0
<script type="text/javascript">
ga('set', 'dimension2', '{% if template contains 'collection' %}category{% elsif template contains 'product' %}product{% elsif template contains 'search' %}searchresults{% elsif template contains 'index' %}home{% endif %}');

{% if template contains 'product' %}
	ga('set', 'dimension1', 'shopify_US_{{ product.id }}_{% if product.variants.first.id %}{{ product.variants.first.id }}',{% else %}{{ product.variants.id }}{% endif %}');
	ga('set', 'dimension3', '{{ product.price_min | money_without_currency | remove:',' }}');
{% endif %}
</script>

I've followed the instructions posted above, but added a bit of liquid code to customize the variables.

 

My custom dimensions are as follows for the Retail Vertical:

dimension1: ecomm_prodid

dimension2: ecomm_pagetype

dimension3: ecomm_totalvalue

 

0 Likes
Highlighted
Tourist
3 0 2
<!-- Begin Google Analytics Vertical Attributes
  
 		Custom dimensions are as follows for the Retail Vertical:

			dimension1: ecomm_prodid

			dimension2: ecomm_pagetype
	
			dimension3: ecomm_totalvalue -->
  		

<script type="text/javascript">

{% if template contains 'index' %}
	ga('set', 'dimension2', 'home');

{% elsif template contains 'collection' %}
	ga('set', 'dimension2', 'category');

{% elsif template contains 'search' %}
	ga('set', 'dimension2', 'searchresults');
 
{% elsif template contains 'product' %}

	ga('set', 'dimension1', 'shopify_CA_{{ product.id }}_{% if product.variants.first.id %}{{ product.variants.first.id }}'{% else %}{{ product.variants.id }}'{% endif %});

	ga('set', 'dimension2', 'product');
  
  	
  	{% if product.selected_variant.price %}
  	
  	ga('set','dimension3',{{ product.selected_variant.price | money_without_currency | replace: ',', '.' }}); 
	
    {% else %}
  	
    ga('set','dimension3',{{ product.price | money_without_currency | replace: ',', '.' }}); 
	
  	{% endif %}


{% elsif template contains 'cart' %}

    ga('set', 'dimension1', '[{% for item in cart.items %}shopify_CA_{{ item.product_id }}_{{ item.variant_id }}{% unless forloop.last %},{% endunless %}{% endfor %}]');

    ga('set', 'dimension2', 'cart');

    ga('set', 'dimension3', {{cart.total_price | money_without_currency | replace: ',', '.' }});

{% else %}
	ga('set', 'dimension2', 'other');
  
{% endif %}
 
	ga('send', 'pageview');
  
</script>


<!-- End Google Analytics Vertical Attributes -->
Highlighted
Shopify Partner
7 0 0

Hi Carlos_Garcia3

 

Is that code working? Please add some instructions!

Many thanks

0 Likes
Highlighted
Tourist
3 0 2

Hi Alvaro, 

I am still making some implementations to the script, just note that I am not a developer, just a store owner searching on the internet.

 

I found this link that gave me some good ideas, as it said, I paste my script before the closing </head> tag on my liquid theme.

 

I also adjust the code, since my store has variants, so the product ID and price ID get the right info according to the variant.

 

Here the code I am using, not sure if it is working properly yet since I have to wait to see results on the status from the Google Analytics audiences source in my Google Ads account, but the Tag Assistance is showing me the green happy face.

 

<!-- Begin Google Analytics Vertical Attributes
  
 		Custom dimensions are as follows for the Retail Vertical:

			dimension1: ecomm_prodid

			dimension2: ecomm_pagetype
	
			dimension3: ecomm_totalvalue -->

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  	ga('create', 'UA-XXXXXXXX-X', 'auto'); Here your Property ID from your GA

{% if template contains 'index' %}
	ga('set','dimension2', 'home');

{% elsif template contains 'collection' %}
	ga('set','dimension2', 'category');

{% elsif template contains 'search' %}
	ga('set','dimension2', 'searchresults');
 
{% elsif template contains 'product' %}

	ga('set','dimension1', 'shopify_CA_{{ product.id }}_{% if product.variants.first.id %}{{ product.selected_variant.id }}'{% else %}{{ product.variants.id }}'{% endif %});

	ga('set','dimension2', 'product');
  
  	ga('set','dimension3','{% if product.selected_variant.price %}{{ product.selected_variant.price | money_without_currency | replace: ',', '.' }}'{% else %}{{ product.price | money_without_currency | replace: ',', '.' }}'{% endif %});
  	
{% elsif template contains 'cart' %}

    ga('set','dimension1', '[{% for item in cart.items %}shopify_CA_{{ item.product_id }}_{{ item.variant_id }}{% unless forloop.last %},{% endunless %}{% endfor %}]');

    ga('set','dimension2', 'cart');

    ga('set','dimension3', {{cart.total_price | money_without_currency | replace: ',', '.' }});

{% else %}
	ga('set','dimension2', 'other');
  
{% endif %}
 
	ga('send','pageview');

</script>

<!-- End Google Analytics Vertical Attributes -->

 

 

 

0 Likes
Highlighted
Tourist
3 0 2

It is working....

 

Capture d’écran, le 2019-05-24 à 14.51.41.pngCapture d’écran, le 2019-05-24 à 14.51.49.png

0 Likes
Highlighted
Shopify Partner
7 0 0

Hi Carlos, It is working for me too, but I am getting an issue with the ga('send','pageview');

 

Using that code as it is, I am getting 2 pages views hits events per user visit so it is counting double. Basically Shopify is counting  a pageview hit using the native Google Analytic configuration and that code it sending a pageview hit too.

 

Did you check this?

 

I used this code:

 

<script>
  
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  	ga('create', 'XXXXXXXXXX', 'auto');
  
{% if template contains 'index' %}
	ga('set','dimension2', 'home');

{% elsif template contains 'collection' %}
	ga('set','dimension2', 'category');

{% elsif template contains 'search' %}
	ga('set','dimension2', 'searchresults');
 
{% elsif template contains 'product' %}

	ga('set','dimension1', 'shopify_US_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}');

	ga('set','dimension2', 'product');
  
  	ga('set','dimension3', '{% if product.selected_variant.price %}{{ product.selected_variant.price | money_without_currency | replace: ',', '.' }}'{% else %}{{ product.price | money_without_currency | replace: ',', '.' }}'{% endif %});
  	
{% elsif template contains 'cart' %}

    ga('set','dimension1', '{% for item in cart.items %}shopify_US_{{ item.product_id }}_{{ item.variant_id }}{% unless forloop.last %},{% endunless %}{% endfor %}');

    ga('set','dimension2', 'cart');

    ga('set','dimension3', '{{cart.total_price | money_without_currency | replace: ',', '.' }}');

{% else %}
	ga('set','dimension2', 'other');
  
{% endif %}
  
ga('send','pageview');


</script>

 

 

 

 

0 Likes