Copyright 2019 Google LLC. This solution, including any related sample code or data, is made available on an “as is,” “as available,” and “with all faults” basis, solely for illustrative purposes, and without warranty or representation of any kind. This solution is experimental, unsupported and provided solely for your convenience. Your use of it is subject to your agreements with Google, as applicable, and may constitute a beta feature as defined under those agreements. To the extent that you make any data available to Google in connection with your use of the solution, you represent and warrant that you have all necessary and appropriate rights, consents and permissions to permit Google to use and process that data. By using any portion of this solution, you acknowledge, assume and accept all risks, known and unknown, associated with its usage, including with respect to your deployment of any portion of this solution in your systems, or usage in connection with your business, if at all.
- Shoptimizer API Install Guide
This document explains how to build and run the Shoptimizer API (referred to as 'Shoptimizer').
For an explanation of how to integrate Shoptimizer with your existing codebase and for more technical details, see the developer guide.
- An environment capable of hosting Docker containers (for example, Google Cloud Run)
This section describes how to download, build, and run Shoptimizer.
Note: For details on how to run a container image on your chosen platform besides GCP, which is described below, see the documentation for your specific platform.
If you do not have a container host already, you can use Google Cloud Run to host Shoptimizer.
Prerequisites: Using the automated install script requires a Google Cloud project with a billing account attached, as well have having installed the Google Cloud SDK Command-Line Tools.
Git clone the repository:
git clone https://github.com/google/shoptimizer.git
Navigate to the Shoptimizer directory:
cd shoptimizer/shoptimizer_api
Edit the env.sh file:
vim env.sh
Set the following variables to names you choose:
GCP_PROJECT=[YOUR_GCP_PROJECT_NAME]
SOURCE_REPO=[NAME_FOR_YOUR_GIT_REPO_IN_GCP]
Set the GCP project to your target project in your command prompt:
gcloud config set project [YOUR_GCP_PROJECT_NAME]
Run the installation script:
sh install_to_gcp.sh
Set the remote destination for your Cloud project's git repo. You can copy the destination URL from the Source Repo page accessed from your GCP project's admin console, or replace the variables in the command shown below:
git remote add gcp ssh://[YOUR_USERNAME]@source.developers.google.com:2022/p/[YOUR_GCP_PROJECT_NAME]/r/[NAME_FOR_YOUR_GIT_REPO_IN_GCP]
Finally, push the code to your GCP project's Cloud Source Repository.
git push gcp master
Allow the deployment to run in Cloud Build. This will take several minutes. You can monitor the progress from your GCP project's Cloud Build dashboard in the admin console. If a build fails, something may be wrong with cache files generated during the build. In this case, open Container Registry on the GCP console, delete the directory shoptimizer/cache
and try running the build again.
Congratulations, you should now have Shoptimizer running in Docker on Cloud Run!
This section explains how to set up Shoptimizer on Google Cloud Run using CLI.
You should have Docker installed.
Install the Google Cloud SDK.
After it is installed, configure Docker for gcloud:
gcloud auth configure-docker
If you are not already in the Shoptimizer directory, navigate to that directory with the following command:
cd shoptimizer/shoptimizer_api
Then, build the image:
docker build . -t gcr.io/[project-id]/shoptimizer
(Replace [project-id] with your Google Cloud Platform project ID.)
Push the image you just built to Google Container Registry:
docker push gcr.io/[project-id]/shoptimizer
(Replace [project-id] with your Google Cloud Platform project ID.)
Deploy the container to Cloud Run:
gcloud run deploy --image gcr.io/[project-id]/shoptimizer --platform managed
(Replace [project-id] with your Google Cloud Platform project ID.)
When prompted, select the following options:
Set servicename: shoptimizer
Allow unauthenticated invocations: N
Take note of the URL returned. It should look something like this:
https://shoptimizer-abcde12345-an.a.run.app
Congratulations, you should now have Shoptimizer running in Docker on Cloud Run!
Git clone the repository:
git clone https://github.com/google/shoptimizer.git
Navigate to the Shoptimizer directory:
cd shoptimizer/shoptimizer_api
Run the following command to build the image:
docker build -t shoptimizer .
Optional: To check that the image built correctly, run docker image ls
and confirm that 'shoptimizer' is in the list of images.
After building the image, run the container with the following command:
docker run -d --name shoptimizer -p 8080:8080 -e PORT=8080 -e PRODUCT_TRACKING_FIELD="customLabel4" shoptimizer
Optional: To check that the container started correctly, run docker container ps -a
and check the 'shoptimizer' STATUS.
The shoptimizer container contains the following environment variables:
-
PORT: The port for the gunicorn server that is used to run Shoptimizer.
-
PRODUCT_TRACKING_FIELD: A field used to track the performance of optimized products in Google Ads. Specifically, when products are modified by Shoptimizer, this field will be set to one of three options:
- SANITIZED: Invalid data was removed or corrected. If this had not been done the product would have been disapproved.
- OPTIMIZED: Data was modified in an attempt to improve performance, but the original data was not incorrect.
- SANITIZED_AND_OPTIMIZED: The product was both sanitized and optimized.
These three values can be used as filters in Google Ads to track the performance of products affected by Shoptimizer. Setting this variable to an empty string will disable tracking. The default value is 'customLabel4'.
You can check if your container is working correctly by sending a request to the following URL:
{HOST}:{PORT}/shoptimizer/v1/health
For example, if you are running the container on localhost with a port of 8080, you can test it by going to the following URL:
http://localhost:8080/shoptimizer/v1/health
Make a request to the API to check it is working by running the following command:
curl -H \
"Authorization: Bearer $(gcloud auth print-identity-token)" \
[YOUR_SHOPTIMIZER_URL]/shoptimizer/v1/health
Example:
curl -H \
"Authorization: Bearer $(gcloud auth print-identity-token)" \
https://shoptimizer-adcde12345-an.a.run.app/shoptimizer/v1/health
It should return, Success
.
If you do not see Success
, check the Google Cloud Platform > Cloud Run UI and make sure your container is up and running correctly.
The Shoptimizer API by default does not provide authentication or authorization mechanisms. If you want to secure the container, use the security mechanisms provided by your container host.
For example, if using Google Cloud Run, restrict the container to only allow authenticated invocations and use 'Permissions' to grant access to your application's service account.
To update Shoptimizer, check the Releases section to download new versions of the API as they are released, and perform a re-deployment of the container.