Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,66 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
working_directory: /app
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: docker:17.05.0-ce-git
environment:
DOCKER_REGISTERY: tribeplatform/google-analytics
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
parameters:
registery:
type: string
steps:
- checkout
- setup_remote_docker:
version: 19.03.13
- setup_remote_docker
- run:
name: 'Build application Docker image'
command: docker build --cache-from=app -t app .
- deploy:
name: Push application Docker image
name: 'Build and deploy docker image'
command: |
docker build --cache-from=app -t app .
docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
docker tag app "${DOCKER_REGISTERY}:${CIRCLE_SHA1}"
docker push "${DOCKER_REGISTERY}:${CIRCLE_SHA1}"
docker tag app << parameters.registery >>:${CIRCLE_SHA1}
docker push << parameters.registery >>:${CIRCLE_SHA1}
publish-dev:
docker:
- image: tribeplatform/tribecd:0.1.15
- image: tribeplatform/cli:1.0.0
auth:
username: $DOCKER_HUB_USERNAME
password: $DOCKER_HUB_PASSWORD
environment:
DOCKER_REGISTERY: tribeplatform/google-analytics
REVIEW_APP_NAME: google-analytics
REVIEW_APP_ENV: development
REVIEW_APP_REGION: us-east-1
REVIEW_APP_IMAGE_URI: $DOCKER_REGISTERY:$CIRCLE_SHA1
steps:
- checkout
- run:
name: 'Publish Image'
command: tcdi -cu
name: 'Deploy app on DEV environment'
command: |
ops init -i -e ermia@bettermode.com -u $OPS_USERNAME -p $OPS_PASSWORD
ops app create -n google-analytics -i $DOCKER_REGISTERY:$CIRCLE_SHA1
ops service deploy -s google-analytics -i $DOCKER_REGISTERY:$CIRCLE_SHA1
publish-prod:
docker:
- image: tribeplatform/tribecd:0.1.15
- image: tribeplatform/cli:1.0.0
auth:
username: $DOCKER_HUB_USERNAME
password: $DOCKER_HUB_PASSWORD
environment:
DOCKER_REGISTERY: tribeplatform/google-analytics
REVIEW_APP_NAME: google-analytics
REVIEW_APP_ENV: production
REVIEW_APP_REGION: us-east-1
REVIEW_APP_IMAGE_URI: $DOCKER_REGISTERY:$CIRCLE_SHA1
steps:
- checkout
- run:
name: 'Publish Image'
command: tcdi -cu
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
name: 'Deploy app on PRD environment'
command: |
ops init -i -e ermia@bettermode.com -u $OPS_USERNAME -p $OPS_PASSWORD
ops app create -n google-analytics -i $DOCKER_REGISTERY:$CIRCLE_SHA1 -e prd
ops service deploy -s google-analytics -e prd -i $DOCKER_REGISTERY:$CIRCLE_SHA1
workflows:
build_app:
app:
jobs:
- build:
registery: tribeplatform/google-analytics
context: App
filters:
branches:
only:
- master
- dev
- publish-dev:
context: App
requires:
Expand All @@ -80,10 +69,15 @@ workflows:
branches:
only:
- master
- dev
- hold:
type: approval
requires:
- build
filters:
branches:
only:
- master
- publish-prod:
context: App
requires:
Expand Down
190 changes: 142 additions & 48 deletions custom_scripts/head.liquid
Original file line number Diff line number Diff line change
@@ -1,58 +1,152 @@
{%- if settings.measurementId and settings.measurementId.size > 0 -%}
{%- assign measurementChar = settings.measurementId | slice: 0 -%}
{%- assign isNew = measurementChar == "G" -%}
{%- assign isNew = measurementChar = = "G" -%}
{%- if isNew -%}
<script
async
src="https://www.googletagmanager.com/gtag/js?id={{ settings.measurementId }}"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{- settings.measurementId -}}', { {% if anonymize %}'anonymize_ip': true,{% endif %} 'send_page_view': false });
gtag('set', {'user_id': '{{ member.id }}'});
function onPageView(data) {
gtag('event', 'page_view', {
page_title: data.title,
page_path: data.page,
});
}
if (window.Tribe) {
window.Tribe.on('pageView', onPageView);
}
window.BM.on('ready', () => {
window.BM.scriptManager.register({
name: 'google-analytics',
consentCategory: 'analytics',
load: () => {
// Load script
const script = document.createElement('script');
script.async = true;
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-123456';
document.head.appendChild(script);

// Initialize Google Analytics
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '{{- settings.measurementId -}}', { {% if anonymize %}'anonymize_ip': true,{% endif %} 'send_page_view': false });
gtag('set', {
'user_id': '{{- member.id -}}'
});


// Listen for page views
function onPageView(data) {
gtag('event', 'page_view', {
page_title: data.title,
page_path: data.page,
});
}
if (window.Tribe) {
window.ga4PageViewListener = window.Tribe.on('pageView', onPageView);
}
},
unload: () => {
// Remove script
const script = document.querySelector('script[src*="googletagmanager.com/gtag/js"]');
if (script) {
script.remove();
}

// Remove dataLayer
window.dataLayer = undefined;

// Remove page view listener
if (window.ga4PageViewListener) {
window.ga4PageViewListener.removeAllListeners();
window.ga4PageViewListener = undefined;
}
},
getCookiesToRemove: () => {
const getCookieOptions = () => {
try {
const domainParts = window.location.hostname.split('.')
const removalDomain = `.${domainParts.slice(-2).join('.')}`
return { domain: removalDomain, path: '/' }
} catch {
return { domain: window.location.hostname, path: '/' }
}
}
const options = getCookieOptions()
return [
{ name: '_ga', options },
{ name: '_ga_{{ settings.measurementId }}', options },
]
},
})
});
</script>
{%- endif -%} {%- unless isNew -%}
{%- endif -%}
{%- unless isNew -%}
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
window.BM.on('ready', () => {
window.BM.scriptManager.register({
name: 'google-analytics-legacy',
consentCategory: 'analytics',
load: () => {
// Load script
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

// Initialize Google Analytics
ga('create', '{{ settings.measurementId }}', 'auto');
{% if anonymize -%}
ga('set', 'anonymizeIp', true);
{% endif -%}

ga('set', 'userId', '{{ member.id }}');

// Listen for page views
const onPageView = (data) => {
ga('send', {
'hitType': 'pageview',
'page': data.page,
'title': data.title,
});
}
if (window.Tribe) {
window.ga4PageViewListener = window.Tribe.on('pageView', onPageView);
}
},
unload: () => {
// Remove script
const script = document.querySelector('script[src*="google-analytics.com/analytics.js"]');
if (script) {
script.remove();
}

// Remove dataLayer
window.dataLayer = undefined;

ga('create', '{{ settings.measurementId }}', 'auto');
{% if anonymize -%}
ga('set', 'anonymizeIp', true);
{% endif -%}
ga('set', 'userId', '{{ member.id }}');
function onPageView(data) {
ga('send', {
'hitType': 'pageview',
'page': data.page,
'title': data.title,
});
}
if (window.Tribe) {
window.Tribe.on('pageView', onPageView);
}
// Remove page view listener
if (window.ga4PageViewListener) {
window.ga4PageViewListener.removeAllListeners();
window.ga4PageViewListener = undefined;
}
},
getCookiesToRemove: () => {
const getCookieOptions = () => {
try {
const domainParts = window.location.hostname.split('.')
const removalDomain = `.${domainParts.slice(-2).join('.')}`
return { domain: removalDomain, path: '/' }
} catch {
return { domain: window.location.hostname, path: '/' }
}
}
const options = getCookieOptions()
return [
{ name: '_ga', options },
{ name: '_ga_{{ settings.measurementId }}', options },
]
}
})
})
</script>
{%- endunless -%}
{%- endif -%}