如何将Google Ads再营销标签添加到Shopify

如何将Google Ads再营销标签添加到Shopify的简单步骤指南(使用最新功能)

第一步:获取你的受众来源标签ID
1. 登录Google Ads,然后在左侧菜单中选择 Tools > Audience manager

Google Ads Audience Manager

从顶部菜单中,点击“Your data sources”。

Google Ads Your Data Sources

在这里你会看到所有面板,点击Google Ads标签的三点菜单,然后选择“edit source”。如果没有这个选项,点击“设置标签”。

Google Ads Tag Edit Source

或者访问此URL:[](https://ads.google.com/aw/audiences/management/datasources/tagsetup)

选择以下选项:

  • Remarketing
    • Collect data on specific actions people performed on your website to show personalized ads.
  • Business Type
    • Retail

点击“Save and continue”。

Google Ads Edit Data Source Step 1

点击“Install the tag yourself”。

Google Ads Re-install the tag

复制如下图所示的数字来源标签ID以备后用。我们将把这个来源标签ID添加到下面的脚本中。

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

第二步:将追踪代码添加到theme.liquid

1. 登录你的Shopify管理面板。
2. 打开主题编辑器,路径为:在线商店 > 主题。
3. 现在选择操作 > 编辑代码。

点击布局文件夹中的 `theme.liquid` 文件。

从下面的代码示例中,编辑 code settings startcode settings end 之间的值。不要更改其他内容,否则可能会破坏功能。以下是你可以编辑的部分

Edit Remarketing Tag

将以下代码复制到文本编辑器中,并将 fa_google_ads_audience_tag_id 的值替换为你的受众标签ID。

默认情况下,代码设置为美国,如果你针对的是其他国家,请将 fa_product_id_alpha2_code 的值更改为你的目标国家的alpha2代码。例如,英国是GB。你可以在这里找到完整的列表:国家代码

接下来的步骤需要你检查Google Merchant Center中的产品ID,路径为:产品 > 列表。并查看你使用的ID。

  • 如果ID看起来像 shopify_US_81191654332_1055121650148,则保持 fa_product_id 设置为默认。
  • 如果ID看起来像 1055121650148,则将 fa_product_id 的值设置为 product_id
  • 如果ID看起来像主ID 81191654332,则将 fa_product_id 的值设置为 parent_id
  • 如果ID看起来像SKU,则将 fa_product_id 的值设置为 sku

更新代码设置后,将其粘贴到 theme.liquid 文件的 <head></head> 标签之间。

<!-- Google Ads Remarketing Tag By FeedArmy Version 2.17 START -->
<!-- FeedArmy tutorial found at https://feedarmy.com/kb/adding-google-adwords-remarketing-tag-to-shopify/ -->
<!-- CODE SETTINGS START -->
<!-- CODE SETTINGS START -->
<!-- Please add your Google Ads Audience Source Tag ID -->
{% assign fa_google_ads_audience_tag_id = 123456789 %}
<!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
{% assign fa_product_id_alpha2_code = 'US' %}
<!-- set your product id values are default, product_id, parent_id, sku-->
{% assign fa_product_id = 'default' %}
<!-- CODE SETTINGS END -->
<!-- CODE SETTINGS END -->
<!-- ==================================== -->
<!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->
{% if fa_google_coding %}{% assign fa_google_coding = true %}{%- else -%}{% assign fa_google_coding = false %}{%- endif -%}
{% if fa_google_coding == false %}
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ fa_google_ads_audience_tag_id }}"></script>
{%- endif -%}
{%- assign fa_current_variant = product.selected_or_first_available_variant -%}
{%- if cart.currency.iso_code == 'GBP' or cart.currency.iso_code == 'USD' or cart.currency.iso_code == 'CAD' or cart.currency.iso_code == 'AUD' or cart.currency.iso_code == 'BWP' or cart.currency.iso_code == 'BND' or cart.currency.iso_code == 'DOP' or cart.currency.iso_code == 'GTQ' or cart.currency.iso_code == 'HKD' or cart.currency.iso_code == 'INR' or cart.currency.iso_code == 'ILS' or cart.currency.iso_code == 'YEN' or cart.currency.iso_code == 'KES' or cart.currency.iso_code == 'KOR' or cart.currency.iso_code == 'LBP' or cart.currency.iso_code == 'MYR' or cart.currency.iso_code == 'MXN' or cart.currency.iso_code == 'NPR' or cart.currency.iso_code == 'NZD' or cart.currency.iso_code == 'NIO' or cart.currency.iso_code == 'NGN' or cart.currency.iso_code == 'PKR' or cart.currency.iso_code == 'CNY' or cart.currency.iso_code == 'PHP' or cart.currency.iso_code == 'SGD' or cart.currency.iso_code == 'LKR' or cart.currency.iso_code == 'CHF' or cart.currency.iso_code == 'TWD' or cart.currency.iso_code == 'TSH' or cart.currency.iso_code == 'THB' or cart.currency.iso_code == 'UGX' or cart.currency.iso_code == 'KWD' -%}
{% if template contains 'product' %}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:',' -%}
{% elsif template contains 'cart' %}
{%- assign fa_product_price = cart.total_price | money_without_currency | remove:',' -%}
{% endif %}
{%- else -%}
{% if template contains 'product' %}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{% elsif template contains 'cart' %}
{%- assign fa_product_price = cart.total_price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{% endif %}
{%- endif -%}
{%- if fa_product_id == 'default' -%}
{%- capture fa_product_id_value -%}shopify_{{ fa_product_id_alpha2_code }}_{{ product.id }}_{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'product_id' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'parent_id' -%}
{%- capture fa_product_id_value -%}{{product.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'sku' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.sku }}{%- endcapture -%}
{%- endif -%}
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-{{ fa_google_ads_audience_tag_id }}');
</script>
{% if template contains 'collection' %}
{% assign fa_event = 'view_item_list' %}
{% elsif template contains 'product' %}
{% assign fa_event = 'view_item' %}
{% elsif template contains 'search' %}
{% assign fa_event = 'view_search_results' %}
{% elsif template contains 'cart' %}
{% assign fa_event = 'add_to_cart' %}
{% elsif template contains 'index' %}
{% assign fa_event = 'home' %}
{% else %}
{% assign fa_event = 'other' %}
{% endif %}
<script>
  gtag('event', '{{ fa_event }}', {
    'send_to': 'AW-{{ fa_google_ads_audience_tag_id }}',
  	  {% if template contains 'product' or template contains 'cart' %}'value': {{ fa_product_price }},{% endif %}
	{% if template contains 'product' %}
    'items': [{
			'id': '{{fa_product_id_value}}',
      'google_business_vertical': 'retail'
    }]
	{% elsif template contains 'cart' %}
	'items': [
	{% for item in cart.items %}
	{
		{% if fa_product_id == 'default' %}
			'id': 'shopify_{{ fa_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}',
		{% elsif fa_product_id == 'product_id' %}
			'id': '{{ item.variant_id }}',
		{% elsif fa_product_id == 'parent_id' %}
			'id': '{{ item.product_id }}',
		{% elsif fa_product_id == 'sku' %}
			'id': '{{ item.sku }}',
		{% endif %}
      'google_business_vertical': 'retail'
    },
	{% endfor %}
	]
	{% endif %}
  });
</script>
<!-- Google Ads Remarketing Tag By FeedArmy Version 2.17 END -->

现在进入设置 > 结账。

向下滚动直到你看到订单处理 > 额外脚本。

从下面的代码示例中,编辑 code settings startcode settings end 之间的值。不要更改其他内容,否则可能会破坏功能。我已经高亮显示了你可以编辑的部分。

Edit Remarketing Tag Options

将以下代码复制到文本编辑器中,并将 fa_google_ads_audience_tag_id 的值替换为你的受众标签ID。

默认情况下,代码设置为美国。如果你针对的是其他国家,请将 fa_product_id_alpha2_code 的值更改为你的目标国家的alpha2代码。例如,英国是GB。你可以在这里找到完整的列表:国家代码

接下来的步骤需要你检查Google Merchant Center中的产品ID,路径为:产品 > 列表。并查看你使用的ID。

  • 如果ID看起来像 shopify_US_81191654332_1055121650148,则保持 fa_product_id 设置为默认。
  • 如果ID看起来像 1055121650148,则将 fa_product_id 的值设置为 product_id
  • 如果ID看起来像主ID 81191654332,则将 fa_product_id 的值设置为 parent_id
  • 如果ID看起来像SKU,则将 fa_product_id 的值设置为 sku

你完成代码后,将其粘贴到额外脚本设置中并保存。

<!-- Google Ads Remarketing Tag By FeedArmy 2021 Version 2.17 START -->
<!-- FeedArmy tutorial found at https://feedarmy.com/kb/adding-google-adwords-remarketing-tag-to-shopify/ -->
<!-- CODE SETTINGS START -->
<!-- CODE SETTINGS START -->
<!-- Please add your Google Ads Audience Source Tag ID -->
{% assign fa_google_ads_audience_tag_id = 123456789 %}
<!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
{% assign fa_product_id_alpha2_code = 'US' %}
<!-- set your product id values are default, product_id, parent_id, sku-->
{% assign fa_product_id = 'default' %}
<!-- CODE SETTINGS END -->
<!-- CODE SETTINGS END -->
<!-- ==================================== -->
<!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->
{% if fa_google_coding %}{% assign fa_google_coding = true %}{%- else -%}{% assign fa_google_coding = false %}{%- endif -%}
{% if fa_google_coding == false %}
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ fa_google_ads_audience_tag_id }}"></script>
{%- endif -%}
{%- assign fa_current_variant = product.selected_or_first_available_variant -%}
{%- if checkout.currency == 'GBP' or checkout.currency == 'USD' or checkout.currency == 'CAD' or checkout.currency == 'AUD' or checkout.currency == 'BWP' or checkout.currency == 'BND' or checkout.currency == 'DOP' or checkout.currency == 'GTQ' or checkout.currency == 'HKD' or checkout.currency == 'INR' or checkout.currency == 'ILS' or checkout.currency == 'YEN' or checkout.currency == 'KES' or checkout.currency == 'KOR' or checkout.currency == 'LBP' or checkout.currency == 'MYR' or checkout.currency == 'MXN' or checkout.currency == 'NPR' or checkout.currency == 'NZD' or checkout.currency == 'NIO' or checkout.currency == 'NGN' or checkout.currency == 'PKR' or checkout.currency == 'CNY' or checkout.currency == 'PHP' or checkout.currency == 'SGD' or checkout.currency == 'LKR' or checkout.currency == 'CHF' or checkout.currency == 'TWD' or checkout.currency == 'TSH' or checkout.currency == 'THB' or checkout.currency == 'UGX' or checkout.currency == 'KWD' -%}
{% if template contains 'product' %}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:',' -%}
{% elsif template contains 'cart' %}
{%- assign fa_product_price = cart.total_price | money_without_currency | remove:',' -%}
{% endif %}
{%- else -%}
{% if template contains 'product' %}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{% elsif template contains 'cart' %}
{%- assign fa_product_price = cart.total_price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{% endif %}
{%- endif -%}
{%- if fa_product_id == 'default' -%}
{%- capture fa_product_id_value -%}shopify_{{ fa_product_id_alpha2_code }}_{{ product.id }}_{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'product_id' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'parent_id' -%}
{%- capture fa_product_id_value -%}{{product.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'sku' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.sku }}{%- endcapture -%}
{%- endif -%}
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-{{ fa_google_ads_audience_tag_id }}');
</script>
{% if template contains 'collection' %}
{% assign fa_event = 'view_item_list' %}
{% elsif template contains 'product' %}
{% assign fa_event = 'view_item' %}
{% elsif template contains 'search' %}
{% assign fa_event = 'view_search_results' %}
{% elsif template contains 'cart' %}
{% assign fa_event = 'add_to_cart' %}
{% elsif template contains 'index' %}
{% assign fa_event = 'home' %}
{% else %}
{% assign fa_event = 'other' %}
{% endif %}
<script>
  gtag('event', '{{ fa_event }}', {
    'send_to': 'AW-{{ fa_google_ads_audience_tag_id }}',
  	  {% if template contains 'product' or template contains 'cart' %}'value': {{ fa_product_price }},{% endif %}
	{% if template contains 'product' %}
    'items': [{
			'id': '{{fa_product_id_value}}',
      'google_business_vertical': 'retail'
    }]
	{% elsif template contains 'cart' %}
	'items': [
	{% for item in cart.items %}
	{
		{% if fa_product_id == 'default' %}
			'id': 'shopify_{{ fa_product_id_alpha2_code }}_{{ item.product_id }}_{{ item.variant_id }}',
		{% elsif fa_product_id == 'product_id' %}
			'id': '{{ item.variant_id }}',
		{% elsif fa_product_id == 'parent_id' %}
			'id': '{{ item.product_id }}',
		{% elsif fa_product_id == 'sku' %}
			'id': '{{ item.sku }}',
		{% endif %}
      'google_business_vertical': 'retail'
    },
	{% endfor %}
	]
	{% endif %}
  });
</script>
<!-- Google Ads Remarketing Tag By FeedArmy 2021 Version 2.17 END -->

检查结果

截至撰写本文时,Google Tag Assistant 不会检查在 gtag 再营销代码中添加的值。因此,你需要查看源代码以确认。

1. 打开浏览器的开发者工具:
在你的商店页面上,右键点击并选择“检查”或按 `F12` 打开开发者工具。

2. 查看页面源代码:
在“元素”标签中,搜索你添加的再营销代码片段。

3. 确认代码:
确认 `YOUR_TAG_ID` 和其他自定义值已正确替换,并且代码在正确的位置加载。

通过这些步骤,你可以确保再营销代码已正确添加并在你的Shopify商店中正常工作。

重要提示!
如果你的浏览器安装了广告拦截器,Google Tag Assistant 将显示红色标签。禁用或移除广告拦截器以查看蓝色图标。

你可以手动检查结果,通过右键点击产品登陆页面,然后选择“查看页面源代码”,并搜索“FeedArmy”(按 Ctrl+F)。然后简单检查添加的值。你应该看到类似如下的内容:

<!-- Google Ads Remarketing Tag By FeedArmy START -->
<!-- FeedArmy tutorial found at https://feedarmy.com/adding-google-adwords-remarketing-tag-to-shopify/ -->
<!-- Please add your Google Ads Audience Source Tag ID -->
<!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode
<!-- set your product id values are default, product_id, parent_id, sku-->
<!-- ------------------------------------ -->
<!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->
<!-- Global site tag (gtag.js) - Ads. -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-123456789"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-123456789');
</script>
<!-- Global site tag (gtag.js) - Ads. -->
<script>
  gtag('event', 'view_item', {
    'send_to': 'AW-123456789',
	'value': 490.00,
    'items': [{
	'id': 'shopify_US_244465464459_214781237805',
        'google_business_vertical': 'retail'
    }]
  });
</script>
<!-- Google Ads Remarketing Tag By FeedArmy END -->
滚动至顶部