Conversion Tracking and Dynamic Remarketing Tag instructions for Shopify

Improve your advertising effectiveness by setting up conversion tracking and dynamic remarketing tag on your Shopify website

  1. You will first need to import the FeedOps Google Tag Manager container on your website.
  2. Once Google Tag Manager has been set up, log in to your Shopify admin panel.
  3. In the left-hand menu, go to SALES CHANNELS > Online Store > Themes, then on your live theme, click Actions and select Edit Code.Shopify-Edit-code (1)
Within Edit Code, go to Layout > theme.liquid and paste the following snippet just before the closing </head> tag.

<!-- FeedOps - Dynamic Remarketing - Version 1.1 START -->
<!-- CODE SETTINGS START -->

<!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
{% assign dc_product_id_alpha2_code = 'AU' %}

<!--
set your product id values are default, product_id, parent_id, sku
1. If it looks like shopify_US_81191654332_1055121650148, then keep dc_product_id set to default
2. If it looks like 1055121650148 then set the value dc_product_id to product_id
3. If it looks like the main id 81191654332 then set the value dc_product_id to parent_id
4. If it looks like a sku then set the value dc_product_id to sku
-->
{% assign dc_product_id = 'default' %}

<!-- CODE SETTINGS END -->
<!-- ------------------------------------ -->
<!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->


{% if template contains 'product' %}
{% assign dc_product_price = product.price_min | divided_by: 100.0 %}
{% endif %}


{% if template contains 'collection' %}
{% assign dc_event = 'category' %}
{% elsif template contains 'product' %}
{% assign dc_event = 'product' %}
{% elsif template contains 'search' %}
{% assign dc_event = 'searchresults' %}
{% elsif template contains 'index' %}
{% assign dc_event = 'home' %}
{% endif %}

<script>
dataLayer.push({
{% if dc_event %}
'event': 'DynamicRemarketing',
'ecomm_pagetype': '{{ dc_event }}',
'currency': '{{ shop.currency }}',
{% if template contains 'product' %}'ecomm_totalvalue': {{ dc_product_price }},{% endif %}
{% if template contains 'product' %}
'ecomm_prodid': [
{% if dc_product_id == 'default' %}
'shopify_{{ dc_product_id_alpha2_code }}_{{ product.id }}_{% if product.variants.first.id %}{{ product.variants.first.id }}{% else %}{{ product.variants.id }}{% endif %}'
{% elsif dc_product_id == 'product_id' %}
'{% if product.variants.first.id %}{{ product.variants.first.id }}{% else %}{{ product.variants.id }}{% endif %}'
{% elsif dc_product_id == 'parent_id' %}
'{{ product.id }}'
{% elsif dc_product_id == 'sku' %}
'{% if product.variants.first.id %}{{ product.variants.first.sku }}{% else %}{{ product.variants.sku }}{% endif %}'
{% endif %}
]
{% endif %}
{% endif %}
});
</script>
<!-- FeedOps - Dynamic Remarketing - Version 1.1 END -->
Only update the CODE SETTING attributes based on your requirements.
  1. Within Edit Code, go to Template > product-template.liquid and paste the following snippet just before the closing </head> tag.

    <!-- FeedOps - Dynamic Remarketing - Version 1.1 START -->
    <!-- CODE SETTINGS START -->

    <!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
    {% assign dc_product_id_alpha2_code = 'AU' %}

    <!--
    set your product id values are default, product_id, parent_id, sku
    1. If it looks like shopify_US_81191654332_1055121650148, then keep dc_product_id set to default
    2. If it looks like 1055121650148 then set the value dc_product_id to product_id
    3. If it looks like the main id 81191654332 then set the value dc_product_id to parent_id
    4. If it looks like a sku then set the value dc_product_id to sku
    -->
    {% assign dc_product_id = 'default' %}

    <!-- CODE SETTINGS END -->
    <!-- ------------------------------------ -->
    <!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->

    {% if template contains 'product' %}
    {% assign dc_product_price = product.price_min | divided_by: 100.0 %}
    {% endif %}

    <script>
    document.querySelector('.add-to-cart').addEventListener('click',function () {
    dataLayer.push({
    'event': 'DynamicRemarketing',
    'ecomm_pagetype': 'cart',
    'ecomm_totalvalue': {{ dc_product_price }},
    'currency': '{{ shop.currency }}',
    'ecomm_prodid': [
    {% if dc_product_id == 'default' %}
    'shopify_{{ dc_product_id_alpha2_code }}_{{ product.id }}_{% if product.variants.first.id %}{{ product.variants.first.id }}{% else %}{{ product.variants.id }}{% endif %}'
    {% elsif dc_product_id == 'product_id' %}
    '{% if product.variants.first.id %}{{ product.variants.first.id }}{% else %}{{ product.variants.id }}{% endif %}'
    {% elsif dc_product_id == 'parent_id' %}
    '{{ product.id }}'
    {% elsif dc_product_id == 'sku' %}
    '{% if product.variants.first.id %}{{ product.variants.first.sku }}{% else %}{{ product.variants.sku }}{% endif %}'
    {% endif %}
    ]
    });
    });
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 1.1 END -->
    Again, only update the CODE SETTING attributes based on your requirements.
  2. In the left-hand menu, now go to Settings > Checkout > Additional Scripts > Order Status Page. If you are a Shopify Plus merchant then paste the following snippet. Only update the CODE SETTING attributes based on your requirements.
    NOTE: If you have enabled "Checkout extensibility" on your site, you will not see an option for Order Status Page. See the section below on Checkout extensibility.

    <!-- FeedOps - Dynamic Remarketing - Version 2 START -->
    <!-- CODE SETTINGS START -->

    <!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
    {% assign dc_product_id_alpha2_code = 'AU' %}


    <!--
    set your product id values are default, product_id, parent_id, sku
    1. If it looks like shopify_US_81191654332_1055121650148, then keep dc_product_id set to default
    2. If it looks like 1055121650148 then set the value dc_product_id to product_id
    3. If it looks like the main id 81191654332 then set the value dc_product_id to parent_id
    4. If it looks like a sku then set the value dc_product_id to sku
    -->
    {% assign dc_product_id = 'default' %}

    <!-- CODE SETTINGS END -->
    <!-- ------------------------------------ -->
    <!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->

    {% assign dc_product_price = checkout.total_price | divided_by: 100.0 %}

    {% if order.email %}
        {% assign dc_user_email = order.email %}
    {% else %}
        {% assign dc_user_email = checkout.email %}
    {% endif %}

    {% if checkout.billing_address.phone %}
        {% assign dc_user_phone_number = checkout.billing_address.phone %}
    {% elsif order.phone %}
        {% assign dc_user_phone_number = order.phone %}
    {% elsif billing_address.phone %}
        {% assign dc_user_phone_number = billing_address.phone %}
    {% else %}
        {% assign dc_user_phone_number = order.shipping_address.phone %}
    {% endif %}

    {% if order.customer.first_name %}
        {% assign dc_user_first_name = order.customer.first_name %}
    {% elsif order.shipping_address.first_name %}
        {% assign dc_user_first_name = order.shipping_address.first_name %}
    {% elsif checkout.customer.first_name %}
        {% assign dc_user_first_name = checkout.customer.first_name %}
    {% endif %}

    {% if order.customer.last_name %}
        {% assign dc_user_last_name = order.customer.last_name %}
    {% elsif order.shipping_address.last_name %}
        {% assign dc_user_last_name = order.shipping_address.last_name %}
    {% else %}
        {% assign dc_user_last_name = checkout.customer.last_name %}
    {% endif %}

    {% if checkout.billing_address.street %}
        {% assign dc_order_street = checkout.billing_address.street %}
    {% elsif order.shipping_address.street %}
        {% assign dc_order_street = order.shipping_address.street %}
    {% else %}
        {% assign dc_order_street = billing_address.street %}
    {% endif %}

    {% if checkout.billing_address.city %}
        {% assign dc_order_city = checkout.billing_address.city %}
    {% elsif order.shipping_address.city %}
        {% assign dc_order_city = order.shipping_address.city %}
    {% else %}
        {% assign dc_order_city = billing_address.city %}
    {% endif %}

    {% if checkout.billing_address.province %}
        {% assign dc_order_region = checkout.billing_address.province %}
    {% elsif order.shipping_address.province %}
        {% assign dc_order_region = order.shipping_address.province %}
    {% else %}
        {% assign dc_order_region = billing_address.province %}
    {% endif %}

    {% if checkout.billing_address.zip %}
        {% assign dc_order_postal_code = checkout.billing_address.zip %}
    {% elsif order.shipping_address.zip %}
        {% assign dc_order_postal_code = order.shipping_address.zip %}
    {% else %}
        {% assign dc_order_postal_code = billing_address.zip %}
    {% endif %}

    {% if checkout.billing_address.country_code %}
        {% assign dc_order_country_code = checkout.billing_address.country_code %}
    {% elsif order.shipping_address.country_code %}
        {% assign dc_order_country_code = order.shipping_address.country_code %}
    {% else %}
        {% assign dc_order_country_code = billing_address.country_code %}
    {% endif %}

    {% assign dc_event = 'purchase' %}

    <script>
    {% if first_time_accessed %}
    dataLayer.push({
    {% if dc_event %}
    'event': 'DynamicRemarketing',
    'ecomm_pagetype': '{{ dc_event }}',
    'ecomm_totalvalue': {{ dc_product_price }},
    'order_id': {{ order.order_number }},
    'currency': '{{ shop.currency }}',
    'user_email': '{{ dc_user_email }}',
    'user_phone': '{{ dc_user_phone_number }}',
    'order_user_first_name': '{{ dc_user_first_name }}',
    'order_user_last_name': '{{ dc_user_last_name }}',
    'order_shipping_street': '{{ dc_order_street }}',
    'order_shipping_city': '{{ dc_order_city }}',
    'order_shipping_region': '{{ dc_order_region }}',
    'order_shipping_postal_code': '{{ dc_order_postal_code }}',
    'order_shipping_country_code': '{{ dc_order_country_code }}',
    'ecomm_prodid': [
    {% for item in checkout.line_items %}
    {% if dc_product_id == 'default' %}
    'shopify_{{ dc_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}'
    {% elsif dc_product_id == 'product_id' %}
    '{{ item.variant_id }}'
    {% elsif dc_product_id == 'parent_id' %}
    '{{ item.product_id }}'
    {% elsif dc_product_id == 'sku' %}
    '{{ item.sku }}'
    {% endif %}
    ,
    {% endfor %}
    ]
    {% endif %}
    });
    {% endif %}
    </script>
    <!-- FeedOps - Dynamic Remarketing - Version 2 END -->
    If you are NOT a Shopify Plus merchant, paste the following snippet.

    <!-- FeedOps - Dynamic Remarketing Purchase Page - Version 2 START -->
    <!-- CODE SETTINGS START -->

    <!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
    {% assign dc_product_id_alpha2_code = 'AU' %}


    <!--
    set your product id values are default, product_id, parent_id, sku
    1. If it looks like shopify_US_81191654332_1055121650148, then keep dc_product_id set to default
    2. If it looks like 1055121650148 then set the value dc_product_id to product_id
    3. If it looks like the main id 81191654332 then set the value dc_product_id to parent_id
    4. If it looks like a sku then set the value dc_product_id to sku
    -->
    {% assign dc_product_id = 'default' %}

    <!-- CODE SETTINGS END -->
    <!-- ------------------------------------ -->
    <!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->

    {% assign dc_product_price = checkout.total_price | divided_by: 100.0 %}

    {% if order.email %}
        {% assign dc_user_email = order.email %}
    {% else %}
        {% assign dc_user_email = checkout.email %}
    {% endif %}

    {% if checkout.billing_address.phone %}
        {% assign dc_user_phone_number = checkout.billing_address.phone %}
    {% elsif order.phone %}
        {% assign dc_user_phone_number = order.phone %}
    {% elsif billing_address.phone %}
        {% assign dc_user_phone_number = billing_address.phone %}
    {% else %}
        {% assign dc_user_phone_number = order.shipping_address.phone %}
    {% endif %}

    {% if order.customer.first_name %}
        {% assign dc_user_first_name = order.customer.first_name %}
    {% elsif order.shipping_address.first_name %}
        {% assign dc_user_first_name = order.shipping_address.first_name %}
    {% elsif checkout.customer.first_name %}
        {% assign dc_user_first_name = checkout.customer.first_name %}
    {% endif %}

    {% if order.customer.last_name %}
        {% assign dc_user_last_name = order.customer.last_name %}
    {% elsif order.shipping_address.last_name %}
        {% assign dc_user_last_name = order.shipping_address.last_name %}
    {% else %}
        {% assign dc_user_last_name = checkout.customer.last_name %}
    {% endif %}

    {% if checkout.billing_address.street %}
        {% assign dc_order_street = checkout.billing_address.street %}
    {% elsif order.shipping_address.street %}
        {% assign dc_order_street = order.shipping_address.street %}
    {% else %}
        {% assign dc_order_street = billing_address.street %}
    {% endif %}

    {% if checkout.billing_address.city %}
        {% assign dc_order_city = checkout.billing_address.city %}
    {% elsif order.shipping_address.city %}
        {% assign dc_order_city = order.shipping_address.city %}
    {% else %}
        {% assign dc_order_city = billing_address.city %}
    {% endif %}

    {% if checkout.billing_address.province %}
        {% assign dc_order_region = checkout.billing_address.province %}
    {% elsif order.shipping_address.province %}
        {% assign dc_order_region = order.shipping_address.province %}
    {% else %}
        {% assign dc_order_region = billing_address.province %}
    {% endif %}

    {% if checkout.billing_address.zip %}
        {% assign dc_order_postal_code = checkout.billing_address.zip %}
    {% elsif order.shipping_address.zip %}
        {% assign dc_order_postal_code = order.shipping_address.zip %}
    {% else %}
        {% assign dc_order_postal_code = billing_address.zip %}
    {% endif %}

    {% if checkout.billing_address.country_code %}
        {% assign dc_order_country_code = checkout.billing_address.country_code %}
    {% elsif order.shipping_address.country_code %}
        {% assign dc_order_country_code = order.shipping_address.country_code %}
    {% else %}
        {% assign dc_order_country_code = billing_address.country_code %}
    {% endif %}

    {% assign dc_event = 'purchase' %}

    <!-- Google DRT Code -->
    {% assign google_site_tag_id = '' %}
    {% assign analytics_measurement_id = '' %}
    {% assign google_business_vertical = 'retail' %}
    {% assign google_conversion_label = '' %}

    <!-- Global site tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={{ google_site_tag_id }}"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', '{{ google_site_tag_id }}', { 'allow_enhanced_conversions': true });
     gtag('config', '{{ analytics_measurement_id }}');
    </script>

    <script>
    {% if first_time_accessed %}
      gtag('event', '{{ dc_event }}', {
        'send_to': '{{ google_site_tag_id }}',
        'value': '{{ dc_product_price }}',
        'items': [
                {% for item in checkout.line_items %}
                {
                    {% if dc_product_id == 'default' %}
                        'id': 'shopify_{{ dc_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}',
                    {% elsif dc_product_id == 'product_id' %}
                        'id': '{{ item.variant_id }}',
                    {% elsif dc_product_id == 'parent_id' %}
                        'id': '{{ item.parent_id }}',
                    {% elsif dc_product_id == 'sku' %}
                        'id': '{{ item.sku }}',
                    {% endif %}
                        'google_business_vertical': 'retail'
                    }
                    {% if forloop.last == false %}
                        ,
                    {% endif %}
                {% endfor %}
                ]
      });
    {% endif %}
    </script>

    <!-- Conversion Event Snippet -->
    <script>
      {% if first_time_accessed %}
      var ec_user_data = {
        'email': '{{dc_user_email}}',
        'phone_number': '{{ dc_user_phone_number }}',
        'address': {
            'first_name': '{{ dc_user_first_name }}',
            'last_name': '{{ dc_user_last_name }}',
            'street': '{{ dc_order_street }}',
            'city': '{{ dc_order_city }}',
            'region': '{{ dc_order_region }}',
            'postal_code': '{{ dc_order_postal_code }}',
            'country': '{{ dc_order_country_code }}'
        }
      };
      gtag('set', 'user_data', {
      'email': '{{dc_user_email}}',
       'phone_number': '{{ dc_user_phone_number }}',
        'address': {
            'first_name': '{{ dc_user_first_name }}',
            'last_name': '{{ dc_user_last_name }}',
            'street': '{{ dc_order_street }}',
            'city': '{{ dc_order_city }}',
            'region': '{{ dc_order_region }}',
            'postal_code': '{{ dc_order_postal_code }}',
            'country': '{{ dc_order_country_code }}'
        }
      });

      gtag('event', 'conversion', {
        'send_to': '{{google_site_tag_id}}/{{google_conversion_label}}',
        'value': '{{dc_product_price}}',
        'currency': '{{ shop.currency }}'
        });
      {% endif %}
    </script>

    <!-- GA4 Pruchase Code -->
    <script>
    {% if first_time_accessed %}
      gtag('event', '{{ dc_event }}', {
          'send_to': '{{ analytics_measurement_id }}',
          'transaction_id': '{{order_id}}',
          'value': {{ dc_product_price }},
          'currency': '{{ shop.currency }}',
          'items': [
                {% for item in checkout.line_items %}
                  {
                    {% if dc_product_id == 'default' %}
                        'item_id': 'shopify_{{ dc_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}',
                    {% elsif dc_product_id == 'product_id' %}
                        'item_id': '{{ item.variant_id }}',
                    {% elsif dc_product_id == 'parent_id' %}
                        'item_id': '{{ item.parent_id }}',
                    {% elsif dc_product_id == 'sku' %}
                        'item_id': '{{ item.sku }}',
                    {% endif %}
                        'item_name': '{{ item.title }}'
                  }
                    {% if forloop.last == false %}
                        ,
                    {% endif %}
                {% endfor %}
              ]
      });
    {% endif %}
    </script>

    <!-- End Google DRT Code -->

    <!-- Facebook Pixel Code -->
    {% assign facebook_pixel_id = '' %}
    {% assign facebook_ecomm_pagetype = 'Purchase' %}

    <script>
      !function(f,b,e,v,n,t,s)
      {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
      n.callMethod.apply(n,arguments):n.queue.push(arguments)};
      if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
      n.queue=[];t=b.createElement(e);t.async=!0;
      t.src=v;s=b.getElementsByTagName(e)[0];
      s.parentNode.insertBefore(t,s)}(window, document,'script',
      'https://connect.facebook.net/en_US/fbevents.js');
      fbq('init', '{{ facebook_pixel_id }}');
      fbq('track', 'PageView');
    </script>
    <noscript>
      <img height="1" width="1" style="display:none"
           src="https://www.facebook.com/tr?id={{Facebook Pixel ID}}&ev=PageView&noscript=1"/>
    </noscript>

    <script>
      {% if first_time_accessed %}
        fbq('track', '{{ facebook_ecomm_pagetype }}', {value: {{ dc_product_price }}, currency: '{{ shop.currency }}', content_type: 'product', content_ids: [
          {% for item in checkout.line_items %}
            {% if dc_product_id == 'default' %}
              'shopify_{{ dc_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}'
            {% elsif dc_product_id == 'product_id' %}
              '{{ item.variant_id }}'
            {% elsif dc_product_id == 'parent_id' %}
              '{{ item.product_id }}'
            {% elsif dc_product_id == 'sku' %}
              '{{ item.sku }}'
            {% endif %}
            ,
          {% endfor %}
          ]});
      {% endif %}
    </script>
    <!-- End Facebook Pixel Code -->

    <!-- Microsoft UET Code -->
    {% assign uet_tag_id = '' %}

    <!-- UET Page Load -->
    <script>
    (function(w,d,t,r,u){var f,n,i;w[u]=w[u]||[],f=function(){var o={ti:{{ uet_tag_id }}};o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")},n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function(){var s=this.readyState;s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)},i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)})(window,document,"script","//bat.bing.com/bat.js","uetq");
    </script>

    <!-- Microsoft DRT -->
    <script>
    {% if first_time_accessed %}
      window.uetq = window.uetq || [];
      window.uetq.push ('event', '', {'ecomm_prodid': [
          {% for item in checkout.line_items %}
            {% if dc_product_id == 'default' %}
              'shopify_{{ dc_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}'
            {% elsif dc_product_id == 'product_id' %}
              '{{ item.variant_id }}'
            {% elsif dc_product_id == 'parent_id' %}
              '{{ item.product_id }}'
            {% elsif dc_product_id == 'sku' %}
              '{{ item.sku }}'
            {% endif %}
            ,
          {% endfor %}
        ], 'ecomm_pagetype': '{{ dc_event }}'});
    {% endif %}
    </script>

    <!-- Microsoft CT -->
    <script>
    {% if first_time_accessed %}
      window.uetq = window.uetq || [];
    window.uetq.push('event', '{{ dc_event }}', {'event_category': 'transaction', 'event_label': 'success', 'revenue_value': {{ dc_product_price }}, 'currency': '{{ shop.currency }}'});
    {% endif %}
    </script>
    <!-- End Microsoft UET Code -->
    <!-- FeedOps - Dynamic Remarketing Purchase Page - Version 2 END -->
    Again, only update the CODE SETTING attributes based on your requirements. You also want to add the values for "google_site_tag_id", "facebook_pixel_id" & "uet_tag_id". If you don't know where to find the missing ids, check how to find the required Google, Facebook & Microsoft IDs guide.

Shopify Checkout Extensibility

If you have enabled Shopify's "Checkout Extensibility" feature, you will not be able to edit the "Order Status" page above. Instead, you will need to use “Customer events” as follows:

  1. In the left-hand menu, now go to Settings > Customer events. Click on Add custom pixel button at the top-right and enter the pixel name as FeedOps Pixel.
  2. Please select the following options for Customer privacy:Screenshot 2024-06-25 at 3.18.54 PM
    • Copy and paste the following script in the Code section.

      Note: Replace GTM-XXXXXXX with your Google Tag Manager Container ID

(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-XXXXXXX');

analytics.subscribe("checkout_completed", event => {
  
  let user_phone;
  if (event.data.checkout.billingAddress.phone) {
    user_phone = event.data.checkout.billingAddress.phone;
  } else if (event.data.checkout.shippingAddress.phone) {
    user_phone = event.data.checkout.shippingAddress.phone;
  } else {
    user_phone = event.data?.checkout?.phone;
  }

  let user_first_name;
  if (event.data.checkout.billingAddress.firstName) {
    user_first_name = event.data.checkout.billingAddress.firstName;
  } else {
    user_first_name = event.data?.checkout?.shippingAddress?.firstName;
  }

  let user_last_name;
  if (event.data.checkout.billingAddress.lastName) {
    user_last_name = event.data.checkout.billingAddress.lastName;
  } else {
    user_last_name = event.data?.checkout?.shippingAddress?.lastName;
  }

  let order_city;
  if (event.data.checkout.shippingAddress.city) {
    order_city = event.data.checkout.shippingAddress.city;
  } else {
    order_city = event.data?.checkout?.billingAddress?.city;
  }

  let order_region;
  if (event.data.checkout.shippingAddress.province) {
    order_region = event.data.checkout.shippingAddress.province;
  } else {
    order_region = event.data?.checkout?.billingAddress?.province;
  }

  let order_postal_code;
  if (event.data.checkout.shippingAddress.zip) {
    order_postal_code = event.data.checkout.shippingAddress.zip;
  } else {
    order_postal_code = event.data?.checkout?.billingAddress?.zip
  }

  let order_country_code;
  if (event.data.checkout.shippingAddress.countryCode) {
    order_country_code = event.data.checkout.shippingAddress.countryCode;
  } else {
    order_country_code = event.data?.checkout?.billingAddress?.countryCode
  }

  let ecomm_prodid = [];
  for (const item of event.data.checkout.lineItems) {
    ecomm_prodid.push(item.id);
  }
  
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
      event: 'DynamicRemarketing',
      ecomm_pagetype: 'purchase',
      ecomm_totalvalue: event.data?.checkout?.totalPrice?.amount,
      order_id: event.data?.checkout?.order.id,
      currency: event.data?.checkout?.currencyCode,
      user_email: event.data?.checkout?.email,
      user_phone: user_phone,
      order_user_first_name: user_first_name,
      order_user_last_name: user_last_name,
      order_shipping_city: order_city,
      order_shipping_region: order_region,
      order_shipping_postal_code: order_postal_code,
      order_shipping_country_code: order_country_code,
      ecomm_prodid: ecomm_prodid
  })
});

To verify that your Dynamic Remarketing and Conversion Tracking works, you can follow Test Dynamic Remarketing Tags & ConversionTracking Test Transaction guides.