# GA4 BigQuery Streaming Ingestion Tool
## Overview
You can export all of your raw events from [Google Analytics 4 properties to BigQuery](https://support.google.com/analytics/answer/9823238#step3&zippy=%2Cin-this-article)
, and ingest the data into the retail API using the [CollectUserEvent method](https://cloud.google.com/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents/collect).
This is a Cloud Function example that collects GA4 schema data stored in
BigQuery tables and ingests the data into the retail API.
The required parameters needed by this tool will be passed through the
environment variables and request bodies.
Please refer to the comments of `userEventIngester` and `envVariables` in
"ingestuserevents.go" file to learn the parameters and variables.
## Before you begin
Contact [email protected] to get allowlisted to use the data harmonization
features.
## Create a Cloud Function
You may follow the toturial
[Your First Function: Go](https://cloud.google.com/functions/docs/first-go) to
learn how to create a Cloud Function. We list the core commands needed below:
1. Enable services:
```
gcloud services enable cloudbuild.googleapis.com
gcloud services enable cloudfunctions.googleapis.com
```
1. Grant permissions:
```
BQProjectID=<ID-of-project-that-has-GA4-BQ-tables>
CFProjectID=<ID-of-project-that-runs-cloud-function>
gcloud projects add-iam-policy-binding ${BQProjectID} \
--member=serviceAccount:${CFProjectID}@appspot.gserviceaccount.com --role=roles/bigquery.jobUser
gcloud projects add-iam-policy-binding ${BQProjectID} \
--member=serviceAccount:${CFProjectID}@appspot.gserviceaccount.com --role=roles/bigquery.dataViewer
```
1. Create an API key to access the retail API
You may follow the instructions in
[Recommendations AI Before you begin](https://cloud.google.com/retail/recommendations-ai/docs/setting-up#create-key)
to create the API key.
1. Create a directory on your local system for the function code:
```
mkdir ~/ingestuserevents
cd ~/ingestuserevents
```
1. Copy the go files to the directory "~/ingestuserevents".
1. Specify the dependencies:
```
go mod init ingestuserevents
go mod tidy
```
1. Deploy the function
```
gcloud functions deploy IngestUserEvents \
--runtime go116 --trigger-http --allow-unauthenticated \
--set-env-vars=\
MetadataProjectID=${CFProjectID},\
RetailProjectNumber=<the-number-of-project-that-enables-the-retail-API>,\
APIKey=<API-key-that-can-access-the-retail-API>,\
TaskName=<any-arbitrary-string>
```
1. Test the function
You should pass some parameters like below in the request body:
```
{
"BQProjectID":"<ID-of-project-that-has-GA4-BQ-tables>",
"BQDatasetID":"<ID-of-dataset-that-has-GA4-BQ-tables>",
"DurationInSeconds":70
}
```
## Create a scheduled job
We want to use the Cloud Scheduler to trigger the Cloud Function:
```
gcloud scheduler jobs create http ingest-user-events \
--description "Ingest user events hourly" \
--schedule "*/1 * * * *" \
--time-zone "Canada/Toronto" \
--uri "https://${REGION}-${PROJECT_ID}.cloudfunctions.net/IngestUserEvents" \
--http-method GET \
--message-body '{"BQProjectID":"<foo>","BQDatasetID":"<bar>","DurationInSeconds":70}'
```
没有合适的资源?快使用搜索试试~ 我知道了~
GoogleRecommendationsAI的样本和示例_Python_Go_下载.zip
共61个文件
py:23个
sh:13个
md:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 41 浏览量
2023-04-23
10:16:13
上传
评论
收藏 56KB ZIP 举报
温馨提示
GoogleRecommendationsAI的样本和示例_Python_Go_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
GoogleRecommendationsAI的样本和示例_Python_Go_下载.zip (61个子文件)
RetailAI-master
JSON
all-events-schema.json 6KB
README.md 56B
LICENSE 11KB
GTM
sGTM.js 6KB
beta
curl
delete_item.sh 403B
event_import.json 211B
gcs_catalog_sample.txt 1KB
gcs_event_import.sh 519B
importEvent.sh 649B
delete_events.sh 1KB
inlineEvent.json 468B
gcs_import_status.sh 441B
gcs_catalog_import.sh 497B
testitem.json 609B
create_item.sh 459B
list_keys.sh 483B
list_catalog_items.sh 502B
register_key.sh 650B
catalog_import.json 217B
gcs_user_event_sample.txt 1KB
get_catalog_item.sh 419B
delete_key.sh 511B
list_events.sh 446B
python
gcs_import_events.py 2KB
copy_events.py 4KB
import_events.py 2KB
list_catalog.py 1KB
list_keys.py 1KB
bq_catalog_export.py 2KB
import_catalog.py 4KB
predict.py 2KB
register_key.py 1KB
lro_operations.py 2KB
delete_catalog_items.py 2KB
gcs_import_catalog.py 2KB
curl_predict.py 1KB
list_events.py 7KB
timestamp_to_zulu.py 247B
unregister_key.py 1KB
README.md 732B
php
predict.php 3KB
python
import_event_inline.py 2KB
predict.py 1KB
import_catalog_inline.py 1KB
README.md 177B
GA4
bqstreaming
ingestuserevents.go 12KB
ga4bqschema.go 8KB
README.md 3KB
README.md 840B
php
autocomplete
style.css 142B
complete.php 1KB
searchform.html 938B
predict.php 2KB
README.md 201B
GCF
demo2.html 428B
python
testsearch.py 265B
recommendation.py 3KB
requirements.txt 20B
testrecs.py 346B
search.py 2KB
demo.html 1KB
共 61 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功