Using a custom Google Analytics code with Buy Button

Shopify Partner
10 0 2

Hi,

Yes the code chunk you pasted is the correct code for the main page. You have to replace the code

UA-XXXXXXX-Y

with your own GA tracking code. The line

ga('linker:autoLink', ['checkout.shopify.com'] );

can be left as is. It tells the GA account to link to the shopify checkout domain (I assume it whitelists checkout.shopify.com so that when the code you placed on that page calls this domain, it is allowed).

 

wow 5 months late haha sorry I missed it at the time.

0 Likes
New Member
1 0 0

Thank you so much for such a thoughtful post! This was a huge win for me. However, I'm running into one problem: it doesn't appear as the though cross-domain tracking aspect is working. I think it's because we can't append the linker paramater to the "thank you" confirmation URL...? 

I've recorded the tag flow, and run the debugger and it's overwriting the source/medium as "direct" on the final purchase conformation page, as well as starting a google analytics new session, and assigning a new client ID. Any ideas? Thanks so much!

0 Likes
New Member
2 0 1

I've been working on trying to get this to work as well. Once I set up cross-domain tracking, I used this script in my Checkout additional scripts section:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('set', 'linker', {'domains': ['mainwebsite.com']});
gtag('js', new Date());

gtag('config', 'UA-XXXXXXXXX-X');
gtag('event', 'purchase', {transaction_id: {{checkout.order_number}}, value: {{checkout.subtotal_price}}, shipping: {{checkout.shipping_price}}});
</script>

When using Tag Assistant, I can see that it is pulling the order id #, the subtotal price, and shipping price. However, it is pulling it without the decimal, i.e. a $30.00 order is showing as $3000. Also, cannot get it to be able to pull a list of the line items. Attached is what the tag manager assistant is showing (was for order #1016, for an item at $30 and shipping at $4.95). Hoping someone will be able to modify this to make it work perfectly.

 

0 Likes
Shopify Partner
20 0 2

That thread seems to be the only information on the internet to track sales with Shopify Buy Button, so first of all: BIG THANKS!!

 

Any luck with tweaking it Ron?

0 Likes
New Member
4 0 0

Hey there - did you every figure this out?   I'm trying to use a similar code snipped as you.  It would be awesome if you could share how you have things set up in Google Tag Manager to enable this to work correctly.

0 Likes
Shopify Partner
20 0 2
Hi!

Yes the only thing we did was so simple it blew my mind.

In the css code of the Shopify button (you know, the code you paste on
whatever page you want the buy button), we replaced the domain
mystore-myshopify.com by our domain mystore.com.

That’s it, nothing else. And now google analytics tracks correctly.

It’s insane that every google rep and Shopify rep had absolutely no answer
to that problem when the answer is that easy. It tells a lot about the
level of training those guys have...

I hope you get to implement it quick!
0 Likes

@Improving_CVR Cool to hear that works. With Shopify's new buy button, this is likely possible and works because the person stays on the same domain (your shop's primary custom domain) rather than being taken to the myshopify.com version of the domain upon checking out from the Buy Button.

Run Google Shopping ads? Get the free definitive guide to Google Shopping for Shopify (no optin required): https://www.digitaldarts.com.au/google-shopping
0 Likes
New Member
4 0 0

Hi @Josh_Uebergang @Improving_CVR - any chance you'd be willing to share the code snippet you used here to get it to work?  Mine is below, but I'm running into two issues still:

 

  • Orders values coming over without decimals (two extra "0s" that shouldn't be in the total purchase amount)
  • Some orders not getting tracked all together. 

 

Screen Shot 2019-10-07 at 3.03.47 PM.pngScreen Shot 2019-10-07 at 3.03.40 PM.png

 

 

 

 

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-129291129-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('set', 'linker', {'domains': ['levyelectric.com']});
gtag('js', new Date());

gtag('config', 'UA-129291129-1');
gtag('event', 'purchase', {transactionId: {{checkout.order_number}}, transactionTotal: {{checkout.total_price}};
</script>

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
 'event': 'purchase',
 'transactionId': '{{checkout.order_number}}',
 'transactionTotal': {{checkout.total_price}},
});
</script>

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MB23D4D');</script>
<!-- End Google Tag Manager -->

 

0 Likes