---
# System prepended metadata

title: 'Handover : Member Tag'

---

#  Handover : Member Tag
###### `Data Team`

## To Do List
- [ ] Member Tag 
    - [x] Tool
    - [x] API
    - [x] Bigquery
    - [x] DataStudio
    - [x] Upload to IDeliver
    - [x] Upload to DataStudio
    - [x] [Tag Logic](https://hackmd.io/NGcmcXDBSEyi0vWkaLCHPQ)
- [x] API
    - [x] Structure : Control
    - [x] CloudFunction
    - [x] All Functions 
- [x] Member Tag Tool
    - [x] Structure
    - [x] IDeliver
    - [x] DataStudio 
- [ ] Link
    - [x] [GitHub]( https://github.com/dktunited/taiwan_member_tag ) 
    - [ ] Tutor Document 
        - [ ] [English Version](https://docs.google.com/presentation/d/1yyHTDjQmlkT435md84IrocStZkaa3fio2n-Xy0nFORc/edit?usp=sharing)
        - [ ] [Chinese Version](https://docs.google.com/presentation/d/1wlAukzeXpy3bdTZfDxggSjjqGe-6Wi0AKXiflBowW9A/edit?usp=sharing)
    - [ ] [User Case](https://docs.google.com/presentation/d/1PdsFY4D7oNxS3c8TigkAxZJGiFgbRoa4bGdqhVZjIpI/edit#slide=id.p)
    - [ ] [Tag's Logic and Structure](https://docs.google.com/presentation/d/1sSvEelCYhSnhms3nGA6qDPPMZgXPB0n_SI9stt8og2A/edit?usp=sharing)
    - [ ] Miro : Member Tag Structure https://miro.com/app/board/uXjVPXj34-w=/
----

### Member Tag : 
Audience Generating Tool. Through consumption records/ member edit information/ external information,Get specific and verifiable information, that can be used to determine the profile of the member.

##### Project Location : https://github.com/dktunited/taiwan_member_tag
###### `Bigquery` `S3` `DataStudio` `Node.js` `Google Drive` `GitHub` `Cloud Functions` `IDeliver` `Line`

Generating Tool : Node.js v16.13.0
    Frame Work : Vue 2.6.14

* Page Description 
    * TagView.vue : This is the main page for member tag.
    * main.js : Build All of This Frontend of Tool and Plugin Vue and Other Needed Packages
    * App.vue : Entrance File, This is set up to have two completely different website layouts, depending on if you are logged in or not ,so that is what ExternalView and DashboardView are for. LoginView renders in Externalview. 


API : Node.js v16.13.0
Frame Work : Node MVC

* Function Description
    * audienceController : Get All of Audiences List ( Data Studio and Upload to IDeliver)
    * basicController : Integrating All of Member Informatoin
    * guidelineController 
    * ideliverAudienceUpload
    * lineAudienceUpload
    * memberController : Get and Update Member Information From MongoDB
    * memberSportController
    * sportController : Get Global Sport List and Group them by Every Single Member
    * tagController
    * typeController : Get Global Transaction and relative with member Information finally put in MongoDB

* Not Used List (Mongo and Cloud Run Eliminate)
    * the whole of "models" folder
    * router.js : it can't be used in google drive


### DataBase & Other Platform
* Bigquery
    * member_tags
        * audiences : All Audience's Basic Information
        * data_studio_analysis_audience : Audience's All Transaction
        * data_studio_analysis_audience_event : Audience's All Activity They Do
        * data_studio_analysis_audience_list : Audience Name Correspond to Members
        * data_studio_analysis_audience_tag : Audience's All Tag
        * ec_product_list : EC's Product Lis (Not Used)
        * favor_sport_raw : Member's Favor Sport
        * type_id_raw : Member's Family Type
        * tags : All of Member's Tag (loyalty_card_num Correspond to Tag)
        * tag : Seperating Tag to "tag" and "value" (For Range Search and Show in DashBoard)
        
* S3 
    * Decathlon_Taiwan/data_extraction/audience/:AudienceName : The member's Loyalty_card_num in this Audience that Want to Upload to IDeliver
    * Decathlon_Taiwan/data_extraction/tw_model_gender000 : Model Correspond to Gender
    * 
* DataStudio
    * Channel 9 : Member Tag Search By Enter loyalty_card_num
    * Channel 9-1 : Audience Search and Generate (Link to Member Tags Tool Page)
    * Channel 9-2 : Audience Analysis - Product & Transaction By Enter loyalty_card_num
    * Channel 9-3 : Profile and other By Enter loyalty_card_num
    * Channel 9-4 : Audience Analysis - Product & Transaction By Pre-upload


### Tutorial : Basic Tutorial For Run Member Tag Project
* Step 1 : Build Environment 
    * Install [Visual Studio Code](https://code.visualstudio.com/) / [Node.js v16.13.0](https://nodejs.org/download/release/v16.13.0/node-v16.13.0-x64.msi)
    * Download All Project From [GitHub](https://github.com/dktunited/taiwan_member_tag/tree/audience) : Code => Download ZIP
    * Or "git clone https://github.com/dktunited/taiwan_member_tag.git" => better for updating version
    * Using Visual Stuio Code to Open This Project Folder
    * Add Extended Module(Ctrl+Shift+X) install "npm"  and "vue language fearutres"
* Step 2 : (Test Enviroment API)Give Permision to Use Bigquery or Other Google Service
    * Enter "$env:GOOGLE_APPLICATION_CREDENTIALS='C:\Absolute Path\app-cloud-api.json'" : Give the Absolute Path of This Project
* Step 3 : Start Run This Project's Developing Enviroment : 
    * Open Terminal 
    * Located to The Member Tag Folder "cd memberTagDev" or "cd api" (Go to api folder or memberTagDev folder, Depending on whick tool you want to use)
    * Install All Packages This Project Need "npm install"
    * Tool Running : Enter "npm run serve" or "node server.js" (run api or memberTagDev , Depending on whick tool you want to use)
* Step 4 : (Member Tag Frontend Tool)Update to Formal environment
    * Stop Developing : Ctrl + C
    * Packaging Fianl Result : "npm run build" => it will generate "dist" folder under memberTagDev Folder 
    * Change Path to Fit Google Drive : Open /dist/index.html => Ctrl + H=> search ""/" replace by ""./" => Ctrl + Alt + Enter
    * Upload to Google Drive : Upload All the things within dist 
* Step 5 : Test & Check
    * Open https://dseq6ztlhjjgxrhfkgyolg.on.drv.tw/audience.com/ with Shift to clear cache



### Basic Command 
* Git : 
    * "git status" Checking The Change between Current Version and Previous Version 
    * "git add ." Add All Current Files to The Upload List
    * "git commit -m 'reason for update'" Add Description for this Update
    * "git push" Upload All Files to The main branch
* NPM : 
    * "npm -v" Checking Version
    * "npm init" Initializing and Create Package.json File 
    * "npm install" Follow Package.json to Install All of The Plugin (Packages) we need
    * "npm run serve" Build a Test Enviroment
    * "npm build" Package All The File to One File for Formal Enviroment
* Basic Shell :
    * "cd ./direction" Move to Certain Folder
    * "ls" List All Files in This Folder
    * "cat ./file.txt" Show This File's Content

* Node :
    * "node app.js" Run Certain JS File
    * "node -v" Check Node.js Version


## Other Information
### Resources 
[Drive to Web](https://www.drv.tw/) 將Google Drive與OneDrive內的html文件轉乘網站
[Vuetify](https://vuetifyjs.com/en/) Vue Plugin 可用設計零件
### Test / Formal Environment
Search "Test Environment" or "Formal Environment"
Cross out the next line that you don't need 
Remove # mark the next line that you need
EX: 
```
// Formal Environment
.get('https://us-central1-twdatawarehouse-bsv8.cloudfunctions.net/all-tag-detail')
// Test Environment
// .get('http://127.0.0.1:3000/tag/all')
```



### Upload To IDeliver

#### Structure :
![](https://i.imgur.com/F57yYmV.png)
#### All Link : 
* Jenkins : https://jenkinsfordiscovery.subsidia.org/job/taiwan/job/taiwan_auto_update/
* GitHub : (Audience Branch)
https://github.com/dktunited/taiwan_data_retail_extraction/tree/audience
* Bigquery : twdatawarehouse-bsv8.member_tags.audiences => Show Audience List (Today)
* Cloud Function : 
    * Audience List : https://console.cloud.google.com/functions/details/us-central1/audience-list
    * Upload Audience To S3 : https://console.cloud.google.com/functions/details/us-central1/audiences2
* S3 : preprod.datamining/Decathlon_Taiwan/data_extraction/audience
* RedShift : 
    * Score Document https://docs.google.com/document/d/1ZHTRF7qwVLA5QrieL6cGmeqsjQBJiIxsPRMap50YP3I/edit
    * Table : 
        * cds.d_seg_header
        * cds.f_seg_customer_segmentation 
        * dtm_tw.tw_audience_tmp

### Upload To Bigquery (DataStudio)
Copying loyalty_card_num to Analyze Audience, it only allow 200,000.
Uploading to bigquery, it could over 3,000,000

#### Structure
![](https://i.imgur.com/egbv5nx.png)

#### All Link : 
* Bigquery 
    * data_studio_analysis_audience : Audience's All Transaction
    * data_studio_analysis_audience_event : Audience's All Activity They Do
    * data_studio_analysis_audience_list : Audience Name Correspond to Members
    * data_studio_analysis_audience_tag : Audience's All Tag
* Bigquery Scheduled Queries : update_mins_audience_detail
* Cloud Function 
    * https://console.cloud.google.com/functions/details/us-central1/audiences2 

* OnDemand.js File : Call Scheduled Queries's Function


----
### Favor Sport Build Step

Cloud Run's Job  to Get The member Who Shopped Yesterday 
Weight, EventSite, Transaction to Calculate the Favor Sport

Cloud Run's Code in https://github.com/dktunited/taiwan_member_tag/

#### Upload new image to Container Registry
gcloud build submit --tag gcr.io/twdatawarehouse-bsv8/tag-favor-sport

#### Build Cloud Run's Job
gcloud beta run jobs create favorSport --image=gcr.io/twdatawarehouse-bsv8/sport 
    --service-account=app-cloudrun-api@twdatawarehouse-bsv8.iam.gserviceaccount.com

#### List All of Cloud Run's Job
gcloud beta run jobs list

#### Excute Cloud Run's 
gcloud beta run jobs execute $jobName