From 500fff9da4cec3a09ddb2dfd46a02936e36b311b Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Fri, 26 Oct 2018 15:00:46 +0200 Subject: [PATCH] Added google analytics and automation script for Genymotion --- .travis.yml | 1 + Analytics.md | 37 ++++++++++++++++++++++++++++++++++ LICENSE | 39 +++++++++++++++++++++++++++--------- README.md | 1 + docker/Emulator_x86 | 9 ++++++++- docker/Genymotion | 9 ++++++++- docker/Real_device | 9 ++++++++- release.sh | 3 ++- release_geny.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++ release_real.sh | 2 +- src/appium.sh | 24 +++++++++++++++++++++++ travis.sh | 3 +++ 12 files changed, 171 insertions(+), 14 deletions(-) create mode 100644 Analytics.md create mode 100755 release_geny.sh diff --git a/.travis.yml b/.travis.yml index 32ba704..45802bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ env: - ANDROID_VERSION=8.1 - ANDROID_VERSION=9.0 - REAL_DEVICE=True + - GENYMOTION=True script: bash travis.sh diff --git a/Analytics.md b/Analytics.md new file mode 100644 index 0000000..0866b26 --- /dev/null +++ b/Analytics.md @@ -0,0 +1,37 @@ +# Docker-Android's Anonymous Aggregate User Behaviour Analytics +Docker-Android has begun gathering anonymous aggregate user behaviour analytics and reporting these to Google Analytics. You are notified about this when you start Docker-Android. + +## Why? +Docker-Android is provided free of charge for our internal and external users and we don't have direct communication with its users nor time resources to ask directly for their feedback. As a result, we now use anonymous aggregate user analytics to help us understand how Docker-Android is being used, the most common used features based on how, where and when people use it. With this information we can prioritize some features over other ones. + +## What? +Docker-Android's analytics record some shared information for every event: + +- The Google Analytics version i.e. `1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v) +- The Google Analytics anonymous IP setting is enabled i.e. `1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip) +- The Docker-Android analytics tracking ID e.g. `UA-128205228-1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid) +- The release version of machine, e.g. `Linux_version_4.4.16-boot2docker_(gcc_version_4.9.2_(Debian_4.9.2-10)_)_#1_SMP_Fri_Jul_29_00:13:24_UTC_2016` This does not allow us to track individual users but does enable us to accurately measure user counts vs. event counts (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid) +- Docker-Android analytics hit type, e.g. `event` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t) +- Application type, e.g. `Emulator` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ec) +- Description will contains information about Emulator configuration, e.g. `Processor type`. (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#el) +- Docker-Android application name, e.g. `docker-android` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an) +- Docker-Android application version, e.g. `1.5-p0` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#av) + +With the recorded information, it is not possible for us to match any particular real user. + +As far as we can tell it would be impossible for Google to match the randomly generated analytics user ID to any other Google Analytics user ID. If Google turned evil the only thing they could do would be to lie about anonymising IP addresses and attempt to match users based on IP addresses. + +## When/Where? +Docker-Android's analytics are sent throughout Docker-Android's execution to Google Analytics over HTTPS. + +## Who? +Docker-Android's analytics are accessible to Docker-Android's current maintainers. Contact [@butomo1989](https://github.com/butomo1989) if you are a maintainer and need access. + +## How? +The code is viewable in [this lines](./src/appium.sh#L203-L225). + +## Opting out before starting Docker-Android +Docker-Android analytics helps us, maintainers and leaving it on is appreciated. However, if you want to opt out and not send any information, you can do this by using passing environment variable GA=false to the Docker container. + +## Disclaimer +This document and the implementation are based on the great idea implemented by [Homebrew](https://github.com/Homebrew/brew/blob/master/docs/Analytics.md) diff --git a/LICENSE b/LICENSE index c1d2dee..02eaa4a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,13 +1,34 @@ Copyright 2016 budi utomo -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +This program is subject to the terms of the Apache License, Version 2.0 AND the following amendments on forks and data processing. Thus, this is a Custom Apache 2.0 License, NOT a dual-license model you may choose from. - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +You can obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0 + + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + +## Forks +Additionally to Apache-2.0, when you fork this repo you are required to either remove our Google Analytics tracking ID: UA-128205228-1 or stop usage gathering completely. + +## Data processing agreement +By using this software you agree that the following non-PII (non personally identifiable information) data will be collected, processed and used by the maintainers for the purpose of improving the docker-android project. Anonymisation with respect of the IP address means that only the first two octets of the IP address are collected. + + +By using this software you also grant us a nonexclusive, irrevocable, world-wide, perpetual royalty-free permission to use, modify and publish these data for all purposes, internally or publicly, including the right to sub-license said permission rights. + + +We collect, process and use the following data: + +* Release version of Docker-Android +* Anonymized IP address (only first two octets) +* Country and city +* Date and time when Docker-Android started +* User (it will collect the information about Release Version of Machine) +* Application type, e.g. Emulator or Device or Genymotion +* Emulator configuration, e.g. Processor type, Device name, Appium mode, Selenium grid mode and mobile test mode + +## End of License Information + +More information about anonymized data collection can be seen [here](Analytics.md) diff --git a/README.md b/README.md index d100501..f6b4dc8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@

+[![Analytics](https://ga-beacon.appspot.com/UA-128205228-1/github/butomo1989/docker-android/README.md)](https://github.com/igrigorik/ga-beacon "Analytics") [![Join the chat at https://gitter.im/butomo1989/docker-android](https://badges.gitter.im/butomo1989/docker-android.svg)](https://gitter.im/butomo1989/docker-android?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/butomo1989/docker-android.svg?branch=master)](https://travis-ci.org/butomo1989/docker-android) [![codecov](https://codecov.io/gh/butomo1989/docker-android/branch/master/graph/badge.svg)](https://codecov.io/gh/butomo1989/docker-android) diff --git a/docker/Emulator_x86 b/docker/Emulator_x86 index 6289165..ed1711b 100644 --- a/docker/Emulator_x86 +++ b/docker/Emulator_x86 @@ -92,6 +92,7 @@ ARG BROWSER=android ARG CHROME_DRIVER=2.40 ARG GOOGLE_PLAY_SERVICE=12.8.74 ARG GOOGLE_PLAY_STORE=11.0.50 +ARG APP_RELEASE_VERSION=1.5-p0 ENV ANDROID_VERSION=$ANDROID_VERSION \ API_LEVEL=$API_LEVEL \ PROCESSOR=$PROCESSOR \ @@ -100,7 +101,13 @@ ENV ANDROID_VERSION=$ANDROID_VERSION \ BROWSER=$BROWSER \ CHROME_DRIVER=$CHROME_DRIVER \ GOOGLE_PLAY_SERVICE=$GOOGLE_PLAY_SERVICE \ - GOOGLE_PLAY_STORE=$GOOGLE_PLAY_STORE + GOOGLE_PLAY_STORE=$GOOGLE_PLAY_STORE \ + GA=true \ + GA_ENDPOINT=https://www.google-analytics.com/collect \ + GA_TRACKING_ID=UA-128205228-1 \ + GA_API_VERSION="1" \ + APP_RELEASE_VERSION=$APP_RELEASE_VERSION \ + APP_TYPE=Emulator ENV PATH ${PATH}:${ANDROID_HOME}/build-tools RUN yes | sdkmanager --licenses && \ diff --git a/docker/Genymotion b/docker/Genymotion index 951eaa1..fca3ef7 100644 --- a/docker/Genymotion +++ b/docker/Genymotion @@ -80,6 +80,7 @@ RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA} # noVNC Default Configurations # These Configurations can be changed through -e #================================================ +ARG APP_RELEASE_VERSION=1.5-p0 ENV DISPLAY=:0 \ SCREEN=0 \ SCREEN_WIDTH=1600 \ @@ -89,7 +90,13 @@ ENV DISPLAY=:0 \ TARGET_PORT=6080 \ TIMEOUT=1 \ VIDEO_PATH=/tmp/video \ - LOG_PATH=/var/log/supervisor + LOG_PATH=/var/log/supervisor \ + GA=true \ + GA_ENDPOINT=https://www.google-analytics.com/collect \ + GA_TRACKING_ID=UA-128205228-1 \ + GA_API_VERSION="1" \ + APP_RELEASE_VERSION=$APP_RELEASE_VERSION \ + APP_TYPE=Genymotion #==================== # Install genymotion diff --git a/docker/Real_device b/docker/Real_device index 195a430..bbe6c3f 100644 --- a/docker/Real_device +++ b/docker/Real_device @@ -71,6 +71,7 @@ RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA} # noVNC Default Configurations # These Configurations can be changed through -e #================================================ +ARG APP_RELEASE_VERSION=1.5-p0 ENV DISPLAY=:0 \ SCREEN=0 \ SCREEN_WIDTH=1600 \ @@ -80,7 +81,13 @@ ENV DISPLAY=:0 \ TARGET_PORT=6080 \ TIMEOUT=1 \ VIDEO_PATH=/tmp/video \ - LOG_PATH=/var/log/supervisor + LOG_PATH=/var/log/supervisor \ + GA=true \ + GA_ENDPOINT=https://www.google-analytics.com/collect \ + GA_TRACKING_ID=UA-128205228-1 \ + GA_API_VERSION="1" \ + APP_RELEASE_VERSION=$APP_RELEASE_VERSION \ + APP_TYPE=Device #========================= # Set default variables diff --git a/release.sh b/release.sh index 2abec14..841202a 100755 --- a/release.sh +++ b/release.sh @@ -163,7 +163,8 @@ function build() { echo "[BUILD] Dockerfile: $FILE_NAME" docker build -t $image_version --build-arg ANDROID_VERSION=$v --build-arg API_LEVEL=$level \ --build-arg PROCESSOR=$processor --build-arg SYS_IMG=$sys_img --build-arg IMG_TYPE=$IMG_TYPE \ - --build-arg BROWSER=$BROWSER --build-arg CHROME_DRIVER=$chrome_driver -f $FILE_NAME . + --build-arg BROWSER=$BROWSER --build-arg CHROME_DRIVER=$chrome_driver \ + --build-arg APP_RELEASE_VERSION=$RELEASE -f $FILE_NAME . docker tag $image_version $image_latest done } diff --git a/release_geny.sh b/release_geny.sh new file mode 100755 index 0000000..5efdef7 --- /dev/null +++ b/release_geny.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +if [ -z "$1" ]; then + read -p "Task (build|push|all) : " TASK +else + TASK=$1 +fi + +if [ -z "$2" ]; then + read -p "Release version: " RELEASE +else + RELEASE=$2 +fi + +IMAGE="butomo1989/docker-android" +FILE_NAME=docker/Genymotion + +image_version="$IMAGE-genymotion:$RELEASE" +image_latest="$IMAGE-genymotion:latest" + +function build() { + echo "[BUILD] Image name: $image_version and $image_latest" + echo "[BUILD] Dockerfile: $FILE_NAME" + docker build -t $image_version --build-arg APP_RELEASE_VERSION=$RELEASE -f $FILE_NAME . + docker tag $image_version $image_latest +} + +function push() { + echo "[PUSH] Image name: $image_version and $image_latest" + docker push $image_version + docker push $image_latest +} + +case $TASK in + build) + build + ;; + push) + push + ;; + all) + build + push + ;; + *) + echo "Invalid environment! Valid options: test, build, push, all" + ;; +esac diff --git a/release_real.sh b/release_real.sh index 6d94bf4..ed8f3af 100755 --- a/release_real.sh +++ b/release_real.sh @@ -21,7 +21,7 @@ image_latest="$IMAGE-real-device:latest" function build() { echo "[BUILD] Image name: $image_version and $image_latest" echo "[BUILD] Dockerfile: $FILE_NAME" - docker build -t $image_version -f $FILE_NAME . + docker build -t $image_version --build-arg APP_RELEASE_VERSION=$RELEASE -f $FILE_NAME . docker tag $image_version $image_latest } diff --git a/src/appium.sh b/src/appium.sh index e3769f0..2349f74 100644 --- a/src/appium.sh +++ b/src/appium.sh @@ -200,6 +200,30 @@ function run_appium() { $CMD } +function ga(){ + if [ "$GA" = true ]; then + echo "Collecting data for improving the project" + description="PROCESSOR: ${SYS_IMG}; DEVICE: ${DEVICE}; APPIUM: ${APPIUM}; SELENIUM: ${CONNECT_TO_GRID}; MOBILE_TEST: ${MOBILE_WEB_TEST}" + random_user=$(cat /proc/version 2>&1 | sed -e 's/ /_/g' | sed -e 's/[()]//g' | sed -e 's/@.*_gcc_version/_gcc/g' | sed -e 's/__/_/g' | sed -e 's/Linux_version_//g' | sed -e 's/generic_build/genb/g') + random_user="${APP_RELEASE_VERSION}_${random_user}" + payload=( + --data v=${GA_API_VERSION} + --data aip=1 + --data tid="${GA_TRACKING_ID}" + --data cid="${random_user}" + --data t="event" + --data ec="${APP_TYPE}" + --data ea="${random_user}" + --data el="${description}" + --data an="docker-android" + --data av="${APP_RELEASE_VERSION}" + ) + curl ${GA_ENDPOINT} "${payload[@]}" --silent + else + echo "Nothing to do" + fi +} + if [ "$REAL_DEVICE" = true ]; then echo "Using real device" run_appium diff --git a/travis.sh b/travis.sh index df37532..797d8da 100755 --- a/travis.sh +++ b/travis.sh @@ -13,6 +13,9 @@ else elif [ ! -z "$REAL_DEVICE" ]; then echo "[SUPPORT FOR REAL DEVICE: BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB ]" bash release_real.sh all $TRAVIS_TAG + elif [ ! -z "$GENYMOTION" ]; then + echo "[SUPPORT FOR GENYMOTION: BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB ]" + bash release_genymotion.sh all $TRAVIS_TAG fi echo "Log out of docker hub" docker logout