skip to Main Content

I have a Gatsby site sourcing from Shopify, and I’m having a hard time getting the Acquisition Conversions working.

My guess is that when they go to the Checkout page, since it’s on Shopify’s domain, it sees that as Direct traffic.

My current configuration is:

{
  resolve: `gatsby-plugin-google-analytics`,
  options: {
    trackingId: "...",
    head: true,
    anonymize: false,
    respectDNT: false,
    allowLinker: true,
  },
},

I just added that allowLinker in to test today. Is there anything else I’m missing? I’m not too familiar with analytics I’m just a humble javascript farmer.

Thank you

2

Answers


  1. Google Analytics recently changed their API to version 4 and upon other things, they changed the way the tracking identifier is set to the page. I suppose that the plugins will migrate soon to that changes but in the meantime, this is the only plugin available that works with that new API version: gatsby-plugin-google-gtag. So:

    // In your gatsby-config.js
    module.exports = {
      plugins: [
        {
          resolve: `gatsby-plugin-google-gtag`,
          options: {
            // You can add multiple tracking ids and a pageview event will be fired for all of them.
            trackingIds: [
              "GA-TRACKING_ID", // Google Analytics / GA
              "AW-CONVERSION_ID", // Google Ads / Adwords / AW
              "DC-FLOODIGHT_ID", // Marketing Platform advertising products (Display & Video 360, Search Ads 360, and Campaign Manager)
            ],
            // This object gets passed directly to the gtag config command
            // This config will be shared across all trackingIds
            gtagConfig: {
              optimize_id: "OPT_CONTAINER_ID",
              anonymize_ip: true,
              cookie_expires: 0,
            },
            // This object is used for configuration specific to this plugin
            pluginConfig: {
              // Puts tracking script in the head instead of the body
              head: false,
              // Setting this parameter is also optional
              respectDNT: true,
              // Avoids sending pageview hits from custom paths
              exclude: ["/preview/**", "/do-not-track/me/too/"],
            },
          },
        },
      ],
    }
    

    All the above parameters are optional, just omit them and replace the GA-TRACKING_ID for your real identifier.

    Login or Signup to reply.
  2. I’m not sure if you ever solved it @cYberSport91, but in the year 2021 AD I am trying to do the same. This is what I found:

    Place this snippet in your gatsby-ssr.js or gatsby-browser.js:

    exports.onRenderBody = ({ setPostBodyComponents }) => {
      const attachCode = `
    if (ga) {
      ga('require', 'linker');
      ga('linker:autoLink', ['destination1.com', 'destination2.com']);
    }`
    
      setPostBodyComponents([<script dangerouslySetInnerHTML={{
        __html: attachCode
      }}/>])
    }
    

    Source: Gatsby Git Issues

    (Still waiting to confirm with my client whether this solution works)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search