GithubHelp home page GithubHelp logo

technicalwebanalytics / datalayer-shopify Goto Github PK

View Code? Open in Web Editor NEW
140.0 25.0 93.0 159 KB

A dataLayer integration specific to extracting information from Shopify.

License: MIT License

JavaScript 100.00%

datalayer-shopify's Introduction

Shopify Data Layer

Definition

A data layer helps you collect more accurate analytics data, that in turn allows you to better understand what potential buyers are doing on your website and where you can make improvements. It also reduces the time to implement marketing tags on a website, and reduces the need for IT involvement, leaving them to get on with implementing new features and fixing bugs.

Resources

https://help.shopify.com/themes/liquid/objects

http://www.datalayerdoctor.com/a-gentle-introduction-to-the-data-layer-for-digital-marketers/

http://www.simoahava.com/analytics/data-layer/

Pages / Actions & Variables Guide

You can access the full Pages/Actions & Variables list here: https://docs.google.com/spreadsheets/d/1SB96_v8dwNMGy-GlVJ7DkrmXrezaBYI5V6MLmD-FF8Q/edit?usp=sharing

Pages / Actions

The Page types and descriptions the dataLayer will exist.

Variables

All information the dataLayer is able to extract and the pages they can be extracted from.

GTM Pages & Variables Import

If you are using GTM, you can import the GTM-InitialSetup.json container that sets up most of the GTM Triggers and Variables for you. This is constantly updated but if there are certain configurations that are not present please refer to the guide above and you should be able to set them up yourself.

https://github.com/TechnicalWebAnalytics/dataLayer-shopify/blob/master/GTM-InitialSetup.json

To import the container in GTM navigate to Admin > Import Container.

Under "Choose Container File", upload GTM-InitialSetup.json then choose whether to use a new or existing workspace. If you are unsure, it is always best to use a new workspace that can be merged into an existing workspace when you are satisfied.

Next, you are 9 times out of 10 always going to use merge > Rename conflicting tags, triggers and variables ( always use Rename to be safe ). If you aren't sure why you should use Overwrite, then you most definitely shouldn't be using it.

You can get more information on the changes by clicking on "View Detailed Changes". Anything that is renamed will have "import" appended to the title.

Integration Instructions

Keep note that this is a base template that attempts to exploit Shopify’s data rendering capabilities and create an ease of integration for dataLayers that can be reused across all Shopify sites. Nonetheless, each site could carry variations that may not be completely compatible with this template. There may also be some areas of data we may have missed, may be a new configuration, or we wouldn’t know is necessary for your efforts. It is highly recommended to review the entire implementation and make your own configurations if needed.

Please let us know if you have any questions or concerns and we will be happy to follow up as soon as possible :)

There are 2 types of Installations provided below. Review each option and choose one.


Installation Option 1:

If the Checkout page cannot be edited, use this option. ( Checkout page edits are only available on Shopify Plus. )

Assets

Assets Integration Type Asset Type
theme.liquid ( or your primary theme template ) Modification Layout: Online Store > Themes > ... > Edit HTML/CSS > Layout > theme.liquid ( or primary theme template )
confirmation page Modification Admin Setting: Settings > Checkout > Order Processing > Additional Pixels & Scripts
dataLayer-allPages Creation Snippet: Online Store > Themes > ... > Edit HTML/CSS > Snippets > ( will create Snippet in instructions )
Google Tag Manager or any other Tag Manager Code Creation or Modification This can either be a Snippet ( unless adding to the confirmation page ) or added directly into your Layout

GTM / Tag Manager Installation or Modification

  • Within the theme.liquid layout, place the GTM / Tag Manager container ( snippet or actual code block ) directly below the opening <body> tag.
  • Within the confirmation page the GTM / Tag Manager container ( actual code block ONLY ) should be placed above all additional scripts. Important Note: Snippets cannot be applied to the confirmation page, any scripts MUST be placed as an actual code block.

Create the dataLayer-allPages snippet ( use exact naming and casing! )

  • Create a snippet called dataLayer-allPages and copy over the provided dataLayer-allPages.js in the newly created snippet. In the code, navigate to the “Dynamic Dependencies” section and make any necessary changes.
/**********************
* DYNAMIC DEPENDENCIES
***********************/
        
 __DL__ = {
    dynamicCart: true,  // if cart is dynamic (meaning no refresh on cart add) set to true
    debug: true, // if true, console messages will be displayed
    cart: null,
    wishlist: null,
    removeCart: null
};
        
customBindings = {
    cartTriggers: [],
    viewCart: [],
    removeCartTrigger: [],
    cartVisableSelector: [],
    promoSubscriptionsSelectors: [],
    promoSuccess: [],
    ctaSelectors: [],
    newsletterSelectors: [],
    newsletterSuccess: [],
    searchPage: [],
    wishlistSelector: [],
    removeWishlist: [],
    wishlistPage: [],
    searchTermQuery: [getURLParams('q')], // replace var with correct query
};
        

Add the code to the layouts

  • Within the theme.liquid layout, place this include snippet {% include 'dataLayer-allPages' %} right before the closing </head> tag
  • Within the confirmation page admin settings, copy over the provided dataLayer-allPages.js code directly above the GTM code block. ( Remember, snippets cannot be used in this section so the actual code block must be added )

Prerequisite Library

  • These are already included in the dataLayer build.

Review, Test, Done :)


Installation Option 2:

If the Checkout page can be edited, use this option.

Assets

Assets Integration Type Asset Type
theme.liquid ( or your primary theme template ) Modification Layout: Online Store > Themes > ... > Edit HTML/CSS > Layout > theme.liquid ( or primary theme template )
checkout.liquid Modification Layout: Online Store > Themes > ... > Edit HTML/CSS > Layout > checkout.liquid
dataLayer-allPages Creation Snippet: Online Store > Themes > ... > Edit HTML/CSS > Snippets > ( will create Snippet in instructions )
Google Tag Manager or any other Tag Manager Code Creation or Modification This can either be a Snippet or added directly into your Layout

Instructions ( Option 2 )

GTM / Tag Manager Installation or Modification

  • Within the theme.liquid & checkout.liquid layout, place the GTM / Tag Manager container ( snippet or actual code block ) directly below the opening <body> tag.

Create the dataLayer-allPages Snippet ( use exact naming and casing! )

  • Create a snippet called dataLayer-allPages and copy over the provided dataLayer-allPages.js in the newly created snippet. In the code, navigate to the “Dynamic Dependencies” section and make any necessary changes.
/**********************
* DYNAMIC DEPENDENCIES
***********************/
      
__DL__ = {
  dynamicCart: true,  // if cart is dynamic (meaning no refresh on cart add) set to true
  debug: true, // if true, console messages will be displayed
  cart: null,
  wishlist: null,
  removeCart: null
};
      
customBindings = {
  cartTriggers: [],
  viewCart: [],
  removeCartTrigger: [],
  cartVisableSelector: [],
  promoSubscriptionsSelectors: [],
  promoSuccess: [],
  ctaSelectors: [],
  newsletterSelectors: [],
  newsletterSuccess: [],
  searchPage: [],
  wishlistSelector: [],
  removeWishlist: [],
  wishlistPage: [],
  searchTermQuery: [getURLParams('q')], // replace var with correct query
};

Add the code to the layouts

  • Within the theme.liquid layout, place this include snippet {% include 'dataLayer-allPages' %} right before the closing </head> tag
  • Within the checkout.liquid layout, place this include snippet {% include 'dataLayer-allPages' %} right before the closing </head> tag

Prerequisite Library

  • These are already included in the dataLayer build.
  1. Review, Test, Done :)

datalayer-shopify's People

Contributors

itsjustaballoon avatar mechellewarneke avatar rfortmann-ewolff avatar tannerchung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datalayer-shopify's Issues

Need support!!!!

Can you provide me full support to done re-marketing setup on shopify store?

Potential issue with dataLayer event push on Transaction

This repo was an amazing discovery and really helped with my store setup. I appreciate the work!

I did have a question with the Transaction event. If I'm reading this code correctly here, https://github.com/TechnicalWebAnalytics/dataLayer-shopify/blob/master/dataLayer-allPages.js#L517-L527, it's only pushing a Transaction when debug mode is on. Is this the intended behavior? I noticed I started losing transaction data when I turned off debug. I can leave it on and be fine, but its just cleaner and feels better to have it off when in prod. But I didn't know if there was an intention behind this or if it was an error. Thank you!

Issue parsing product.title with an apostrophe within

Within the dataLayer-allPages.liquid file, references to a product title do not strip apostrophes and this causes an unknown variable error in the console on page load as it splits the string prematurely.

Fairly simple to fix by removing the apostrophe with a Liquid string filter:
{{ product.title | replace: "'", "" }}

{{product.title}} appears within multiple places within the Snippet and would need to replace all instances if this is an issue.

To check if the implementation is doing the same on your site:

Load a product page once you have completed all steps in the Readme,
Inspect the page and check the console for messages, you should see a dictionary of product variables.

Remove cart not working it was getting the data cart response

Remove cart not working it was getting the data cart response

this code block was push data wrong

$(__DL__.removeCartTrigger).click(function(e){
                      var link = $(this).attr("href");
                      console.log(" link  ", link)
                      let targetUrl = e.target.parentElement.href;
                      console.log("target URL", targetUrl)  
                        jQuery.getJSON(link, function (response) {
                            // get Json response
                            
                            console.log("response this is return the current list of items ", response) 
                            __DL__.removeCart = response;
                            var removeFromCart = {
                                'pageType' : 'Cart',
                                'event'    : 'Remove from Cart11',
                                'ecommerce': __DL__.removeCart.items.map(function (line_item) {
                                    return {  
                                        'id'       : line_item.id,
                                        'sku'      : line_item.sku,
                                        'variant'  : line_item.variant_id,
                                        'name'     : line_item.title,
                                        'price'    : (line_item.price/100),
                                        'quantity' : line_item.quantity
                                 
                                    }
                                })

                            };
                            dataLayer.push(removeFromCart);
                            if (__DL__.debug) {
                                console.log("Cart removes "+" :"+JSON.stringify(removeFromCart, null, " "));
                            }
                        });


                   });

Analytics extra is too long (maximum 8000 characters)

When i try to copy paste the "dataLayer-allPages.js" in the confirmation page admin settings i get the message that "Analytics extra is too long (maximum 8000 characters)". Was there some update on the shopify side?

customBindings not detecting clicks on class, ID, or selectors

I'm not sure if I'm doing this correctly or not but I've added classes, IDs, and selectors into the custom binding arrays similar to the format of the bindings that are labeled "do not touch" but when I have GTM Preview up, the events are not showing up when I click the associated buttons like adding a product to the cart.

customBindings = {
  cartTriggers: ['#add-to-cart,.button--cart,[data-label="Add to Cart"]'],
  viewCart: ['#edit-cart,cart'],
  removeCartTrigger: ['.mini-cart__remove,.icon-cross__container'],
  cartVisableSelector: ['.header__cart-count'],
  promoSubscriptionsSelectors: [],
  promoSuccess: [],
  ctaSelectors: [],
  newsletterSelectors: [],
  newsletterSuccess: [],
  searchPage: [],
  wishlistSelector: [],
  removeWishlist: [],
  wishlistPage: [],
  searchTermQuery: [getURLParams('q')], // replace var with correct query
};

shopify plus store question

How to implement "remove from cart" event on Shopify plus store. The native GA4 integration does not have "remove from cart" . So I was curious what are some other ways to implement

Instruction says
Within the checkout.liquid layout, place this include snippet {% include 'dataLayer-allPages' %} right before the closing tag

But, since checkout.liquid will be deprecated what are the other ways of implementing it?

Product Sku & Variant on collections page

The script in your code
'id' : {{product.id | json}},
'sku' : {{product.selected_variant.sku | json}},
'variantId' : {{product.selected_variant.id | json}},
Doesn't work on the collections page. I updated it to
'id' : {{product.id | json}},
'sku' : {{product.variants.first.sku | json}},
'variantId' : {{product.variants.first.id | json}},

The product isn't yet selected on the collections page so it makes sense that selected doesn't work. Hope this is useful

Error in code that breaks checkout datalayer

Hi,

Just found small but significant issue that breaks the checkout. it is in line 511: /** DATALAYER Variable * Checkout & Transaction Data */ where it says "discount.amoun t" instead of correct "discount.amount"

When I did the change it worked just fine :)

How to Use With Cookie Consent Moduels

Is there any way to prevent the snippet in Shopify from sending until a user makes a decision about cookies in a pop-up banner? What would need to be adjusted in the main theme to take that into account?

Repetitive transactionData

This is more of a clarification than an issue.
I cannot understand why the if block code on #538 is needed when we are passing transactionData on #573 and #583. Isn't this just duplicate? Thanks for clarifying.

json needs to be escaped

Sometimes name strings may have a quote or single quote in them which is not escaped when inserting it into the datalayer json.

Add to Cart only works from product page

Add to Cart works normaly when fired from the product page, however, if I add a product from the home screen the event is pushed but it contains no product data

Event from home page:
image

Event from product page:
image

Global cart variable

I'm trying to create my own product delta related to: #25 but the issue is, whenever I pull the global cart variable, it shows the products list but with a quantity of 1. I'm not sure where this 1 is being pushed to the cart variable.

Remove cart not working

i used this data layer with dynamic cart feature enable but remove cart not working.

any one can fixed this issue.

Replace include tag with render

Hi, thank you for providing the datalayer implementation and excellent instructions on how to install it. I noticed that inserting the liquid snippet in theme.liquid you used {% include 'dataLayer-allPages' %}. I had to change the include tag to render in order to make it work since Shopify depreciated the include tag.

Thank you!

Remove from Cart Event Doesn't Push

First of all, thank you for the immense timesaver of a script.

I'm not seeing the "Remove from Cart" event pushed to the DataLayer.

I have a dynamic and non-dynamic cart capability on my site. For the sake of troubleshooting, I set the relevant dynamic dependencies to the following:

dynamicCart: null,
cart: true,
removeCart: true

When I trigger an item removal in my non-dynamic cart, the page reloads minus the item that was removed. The "Remove from Cart" event never fires. However, I can see that the "removeCartTrigger" is firing..

Any thoughts as to what could be happening? Thanks!

Detecting product quantity changes in cart and remove from cart.

There is a remove from cart event but whenever it is fired, I don't see any data provided about what product was removed. Whenever a quantity is dynamically updated as well, it does not identify the product and quantity of the product removed. Can this be added?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.