−Table of Contents
Google Trusted Stores for FoxyCart 2.0
Important This is a new page and experimental code - ensure you properly test any changes to your store
Required Reading
If you haven't already, read through Google's documentation page for Google Trusted Stores.
Requirements
One of the requirements for GTS to work is that the confirmation page is hosted on the same domain as your own website. As FoxyCart serves the receipt confirmation page to the customer for you, you have two options, one incurring an additional fee and one requiring programming work.
Custom Subdomain
Firstly, you can sign up for our custom subdomain feature, which for an additional yearly fee will serve your FoxyCart hosted pages through your domain. This means that your FoxyCart store domain will become something like secure.yourstore.com
instead of yourstore.foxycart.com
.
Custom Receipt
If signing up for our custom subdomain functionality isn't something you can do, the only other option is to redirect the customer automatically from the FoxyCart web receipt to your website - and display the customers receipt on your own site. This will require a redirect header added to the receipt template, and then utilising the API to fetch the customers order information in order to output their receipt information and also the GTS code parameters.
Add the GTS tracking code
Add the following code into the configuration page of your store's FoxyCart administration. Within the cart section, look for the “Add custom header and footer code to your templates”, and add the code to the “Footer” textarea.
{% if cart_is_fullpage or context == "checkout" or context == "receipt" %} <!-- BEGIN: Google Trusted Stores --> <script type="text/javascript"> var gts = gts || []; gts.push(["id", "GTS_ACCOUNT_ID"]); gts.push(["locale", "en"]); // Optional //gts.push(["google_base_offer_id", "ITEM_GOOGLE_SHOPPING_ID"]); //gts.push(["google_base_subaccount_id", "ITEM_GOOGLE_SHOPPING_ACCOUNT_ID"]); //gts.push(["google_base_country", "ITEM_GOOGLE_SHOPPING_COUNTRY"]); //gts.push(["google_base_language", "ITEM_GOOGLE_SHOPPING_LANGUAGE"]); (function() { var scheme = (("https:" == document.location.protocol) ? "https://" : "http://"); var gts = document.createElement("script"); gts.type = "text/javascript"; gts.async = true; gts.src = "https://www.googlecommerce.com/trustedstores/api/js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(gts, s); })(); </script> <!-- END: Google Trusted Stores --> {% if first_receipt_display %} <!-- START Google Trusted Stores Order --> <div id="gts-order" style="display:none;" translate="no"> <span id="gts-o-id">{{ order_id }}</span> <span id="gts-o-domain">www.YOURDOMAIN.com</span> <span id="gts-o-email">{{ customer_email }}</span> <span id="gts-o-country">{{ shipping_address.country }}</span> <span id="gts-o-currency">USD</span> <span id="gts-o-total">{{ total_order }}</span> <span id="gts-o-discounts">-{{ total_discount }}</span> <span id="gts-o-shipping-total">{{ total_shipping }}</span> <span id="gts-o-tax-total">{{ total_tax }}</span> <span id="gts-o-est-ship-date">{{ "now"|date_modify("+1 days")|date("Y-m-d") }}</span> <span id="gts-o-est-delivery-date">{{ "now"|date_modify("+3 days")|date("Y-m-d") }}</span> <span id="gts-o-has-preorder">N</span> <span id="gts-o-has-digital">N</span> {% for item in items %} <span class="gts-item"> <span class="gts-i-name">{{ item.name }}</span> <span class="gts-i-price">{{ item.price_each }}</span> <span class="gts-i-quantity">{{ item.quantity }}</span> <!-- Optional --> <!-- <span class="gts-i-prodsearch-id">ITEM_GOOGLE_SHOPPING_ID</span> <span class="gts-i-prodsearch-store-id">ITEM_GOOGLE_SHOPPING_ACCOUNT_ID</span> <span class="gts-i-prodsearch-country">ITEM_GOOGLE_SHOPPING_COUNTRY</span> <span class="gts-i-prodsearch-language">ITEM_GOOGLE_SHOPPING_LANGUAGE</span> --> </span> {% endfor %} </div> <!-- END Google Trusted Stores Order --> {% endif %} {% endif %}
The above code handles adding the tracking code to the full page cart, checkout and receipt templates, as well as the order information on the receipt page. The order information is only added on the first display of the receipt to prevent any false positives or duplication.
Customise the code
Within the code you pasted, you'll need to edit a few values:
Account ID
Look for the following line and update GTS_ACCOUNT_ID
with your account ID
gts.push(["id", "GTS_ACCOUNT_ID"]);
Google Shopping Information
If you submit feeds to Google Shopping, there are two blocks you can edit. Within the first script block, look for the following code and uncomment by removing the //
from any of the four lines as required:
//gts.push(["google_base_offer_id", "ITEM_GOOGLE_SHOPPING_ID"]); //gts.push(["google_base_subaccount_id", "ITEM_GOOGLE_SHOPPING_ACCOUNT_ID"]); //gts.push(["google_base_country", "ITEM_GOOGLE_SHOPPING_COUNTRY"]); //gts.push(["google_base_language", "ITEM_GOOGLE_SHOPPING_LANGUAGE"]);
Within the second script block, you may also want to include some relevant information for each product. Uncomment the four lines by removing the <!–
at the start and the –>
at the end towards the bottom of the second script block that looks like this and update the placeholders in capitals, removing any lines you don't need:
<!-- <span class="gts-{{ loop.index }}-prodsearch-id">ITEM_GOOGLE_SHOPPING_ID</span> <span class="gts-{{ loop.index }}-prodsearch-store-id">ITEM_GOOGLE_SHOPPING_ACCOUNT_ID</span> <span class="gts-{{ loop.index }}-prodsearch-country">ITEM_GOOGLE_SHOPPING_COUNTRY</span> <span class="gts-{{ loop.index }}-prodsearch-language">ITEM_GOOGLE_SHOPPING_LANGUAGE</span> -->
Store Domain
GTS wants to know your store domain where the customer added the products to the cart, in the format www.example.com
, update the following line with your domain:
<span id="gts-o-domain">www.YOURDOMAIN.com</span>
Currency
If you're in a currency other than USD, update the USD
value within the second script block for the order information on this line:
<span id="gts-o-currency">USD</span>
Delivery Dates
You may also need to edit the shipping and delivery dates (defaulted to 1 day and 3 days from today respectively). Look for this code in the order information and change the days added as required:
<span id="gts-o-est-ship-date">{{ "now"|date_modify("+1 days")|date("Y-m-d") }}</span> <span id="gts-o-est-delivery-date">{{ "now"|date_modify("+3 days")|date("Y-m-d") }}</span>
Preorder/Digital Products
If there are preorder or digital products present in the order, look for the following two lines and update as required to say Y
instead of N
:
<span id="gts-o-has-preorder">N</span> <span id="gts-o-has-digital">N</span>
Validate your javascript
Follow the steps on GTS documentation for Validating your javascript implementation. Note that the Google Trusted Stores badge doesn't appear until your account is activated by Google.