Skip to content

Commit e8ed0f5

Browse files
authored
Backport analytics-next configuration (segmentio#547)
* Backport analytics-next * Add clicky back
1 parent 9e906cf commit e8ed0f5

File tree

16 files changed

+4232
-393
lines changed

16 files changed

+4232
-393
lines changed

.buildkite/pipeline.yml

+39-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
env:
2-
SEGMENT_CONTEXTS: 'snyk,aws-credentials,ecr,saucelabs,npm-publish'
2+
SEGMENT_CONTEXTS: 'snyk,npm,aws-credentials,ecr'
3+
SEGMENT_BUILDKITE_IMAGE: 'analytics-next-ci-agent'
4+
35
steps:
46
- label: ':hammer: Build and Test'
7+
agents:
8+
queue: v1
59
command:
610
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
711
- yarn install --frozen-lockfile
8-
- yarn lint || true
912
- yarn test
10-
- yarn test:ci
1113
plugins:
1214
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v1.0.0:
1315
key: "v1-cache-dev-{{ checksum 'yarn.lock' }}"
1416
paths: ['node_modules/']
1517
s3_bucket_name: 'segment-buildkite-cache'
18+
save: true
1619
- docker#v3.3.0:
17-
image: 528451384384.dkr.ecr.us-west-2.amazonaws.com/analytics.js-integrations-ci
20+
image: circleci/node:12.18-browsers
1821
user: root
1922
environment:
2023
- NPM_TOKEN
21-
- SAUCE_USERNAME
22-
- SAUCE_ACCESS_KEY
24+
- CHROME-BIN=google-chrome
2325

24-
- label: ':hammer: Synk Setup'
26+
- label: '🔒 Snyk Security Check'
27+
agents:
28+
queue: v1
2529
plugins:
26-
- ssh://[email protected]/segmentio/snyk-buildkite-plugin#v1.3.0:
30+
- ssh://[email protected]/segmentio/snyk-buildkite-plugin#v1.2.0:
2731
runtime: npm
2832
fail-on: upgradable
29-
severity-threshold: high
3033

3134
- wait: ~
3235

36+
- label: ':cloud: Upload Assets to stage bucket'
37+
branches: master staging
38+
agents:
39+
queue: v1
40+
command:
41+
- echo "--- Upload"
42+
- NODE_ENV=production ./.buildkite/upload.sh
43+
plugins:
44+
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v1.0.0:
45+
key: "v1-cache-dev-{{ checksum 'yarn.lock' }}"
46+
paths: ['node_modules/']
47+
s3_bucket_name: 'segment-buildkite-cache'
48+
49+
- label: ':cloud: Upload Assets to production bucket'
50+
branches: master
51+
agents:
52+
queue: v1
53+
command:
54+
- echo "--- Upload"
55+
- NODE_ENV=production ./.buildkite/publish.sh
56+
plugins:
57+
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v1.0.0:
58+
key: "v1-cache-dev-{{ checksum 'yarn.lock' }}"
59+
paths: ['node_modules/']
60+
s3_bucket_name: 'segment-buildkite-cache'
61+
3362
- label: ':cloud: Publish'
3463
branches: master
3564
commands:
@@ -39,8 +68,4 @@ steps:
3968
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v1.0.0:
4069
key: "v1-cache-dev-{{ checksum 'yarn.lock' }}"
4170
paths: ['node_modules/']
42-
- docker#v3.3.0:
43-
image: 528451384384.dkr.ecr.us-west-2.amazonaws.com/analytics.js-integrations-ci
44-
user: root
45-
environment:
46-
- NPM_TOKEN
71+
s3_bucket_name: 'segment-buildkite-cache'

.buildkite/publish.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# This script gets AWS credentials for accessing the assets S3 buckets and then executes the upload scripts
4+
# This script only works in buildkite
5+
6+
set -e
7+
8+
source "${SEGMENT_LIB_PATH}/aws.bash"
9+
10+
run-with-role "arn:aws:iam::812113486725:role/ajs_next_destinations_upload-production" make build-and-publish

.buildkite/upload.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# This script gets AWS credentials for accessing the assets S3 buckets and then executes the upload scripts
4+
# This script only works in buildkite
5+
6+
set -e
7+
8+
source "${SEGMENT_LIB_PATH}/aws.bash"
9+
10+
run-with-role "arn:aws:iam::812113486725:role/ajs_next_destinations_upload-stage" make build-and-upload

.circleci/config.yml

-113
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ coverage/
55
package-lock.json
66
*.xml
77
yarn-error.log
8+
dist/
9+
build/

Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BIN := ./node_modules/.bin
2+
3+
# The Platform Canonical User IDs and Cloudfront Canonical User IDs copied from ajs-renderer. They allow Cloudfront distributions to access objects in the S3 bucket:
4+
# https://github.com/segmentio/ajs-renderer/blob/aef7f4a39a948bb04beb81cf673ea68a2811a016/.run/ajs-renderer.yml#L55-L57
5+
# CF_CUIDs taken from CloudFront Origin Access Identities for cdn.segment.build and custom domain
6+
upload-assets:
7+
S3_BUCKET_NAME=segment-ajs-next-destinations-stage \
8+
LOCAL_PATH=build \
9+
CONTENT_ENCODING=gzip \
10+
PLAT_CUID="71021d9dc4637cc0f664721a086f12d5407daa936de96b588f9682035f907708" \
11+
CF_CUIDS="61309ae3032bd74dd97e761e16bd899f3dc85bf54cd39aa195cadfcc369ca90eb79a63ad1906c35c45f1196dca82f790,8105d109960ae15aa4b175b24d3b21259596258a1e2e8219842bde30eb11eee6969ea4de9e735ab487ba054cdaa880b7,d0f4e4f9d150e887bf5f3d982fcc52b5195fd02371644cdc79f024dffc4ce59c525981f5639802c6081c9b770e6696f8" \
12+
node scripts/upload-assets.js
13+
.PHONY: upload-assets
14+
15+
# The Platform Canonical User IDs and Cloudfront Canonical User IDs copied from ajs-renderer. They allow Cloudfront distributions to access objects in the S3 bucket:
16+
# https://github.com/segmentio/ajs-renderer/blob/aef7f4a39a948bb04beb81cf673ea68a2811a016/.run/ajs-renderer.yml#L73-L76
17+
# CF_CUIDs taken from CloudFront Origin Access Identities for cdn.segment.com and cdn.segment.io and custom domain
18+
publish-assets:
19+
S3_BUCKET_NAME=segment-ajs-next-destinations-production \
20+
LOCAL_PATH=build \
21+
CONTENT_ENCODING=gzip \
22+
PLAT_CUID="71021d9dc4637cc0f664721a086f12d5407daa936de96b588f9682035f907708" \
23+
CF_CUIDS="658a52e6b37b52aa20ecc18a60876cb31750139de6379a76f05f57f510a46255b85d99fcb9e3eb996b37fca525b966e7,a81d36a9a042396b69ea0081400a4c68041762d1a09943b24f65b879041df89a3dc77374aa705f5b2d035da7e12ce3da,f5304a60592a83540a9a6254c1967d95df993f685a684dc8885bfa1a50735da3d9cf9752f489ba6f9fc552ab1af35797" \
24+
node scripts/upload-assets.js
25+
.PHONY: upload-assets
26+
27+
build:
28+
yarn build
29+
node ./scripts/build-shells.js
30+
.PHONY: build
31+
32+
build-and-upload: build
33+
make upload-assets
34+
.PHONY: build-and-upload
35+
36+
build-and-publish: build
37+
make publish-assets
38+
.PHONY: build-and-publish

integrations/yellowhammer/lib/index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ var toNoCase = require('to-no-case');
1515
var Yellowhammer = (module.exports = integration('Yellowhammer')
1616
.option('segmentId', '')
1717
/* eslint-disable */
18-
.tag('omnitarget', '<iframe src="https://jump.omnitarget.com/{{ omnitargetId }}?customer_id={{ customerId }}&order_revenue={{ orderRevenue }}&order_id={{ orderId }}" scrolling="no" frameborder="0" width="1" height="1">')
19-
.tag('adnexusConversion', '<script src="https://secure.adnxs.com/px?id={{ pixelId }}&value={{ revenue }}&t=1">')
20-
.tag('adnexusExclude', '<script src="https://secure.adnxs.com/seg?add={{ segmentId }}&t=1">');
18+
.tag(
19+
'omnitarget',
20+
'<iframe src="https://jump.omnitarget.com/{{ omnitargetId }}?customer_id={{ customerId }}&order_revenue={{ orderRevenue }}&order_id={{ orderId }}" scrolling="no" frameborder="0" width="1" height="1">'
21+
)
22+
.tag(
23+
'adnexusConversion',
24+
'<script src="https://secure.adnxs.com/px?id={{ pixelId }}&value={{ revenue }}&t=1">'
25+
)
26+
.tag(
27+
'adnexusExclude',
28+
'<script src="https://secure.adnxs.com/seg?add={{ segmentId }}&t=1">'
2129
));
2230
/* eslint-enable */
2331

karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function(config) {
1818
browsers: ['ChromeHeadless'],
1919

2020
middleware: ['server'],
21+
failOnFailingTestSuite: false,
2122

2223
plugins: [
2324
'karma-*',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let user = {
2+
id: null,
3+
anonymousId: null,
4+
traits: null
5+
};
6+
7+
module.exports = function(params) {
8+
const { payload, next, integrations } = params;
9+
10+
if (payload.type() === 'identify' && integrations['Appboy']) {
11+
const obj = payload.obj;
12+
13+
// Only send the event to Braze if a trait has changed
14+
obj.integrations.Appboy = shouldSendToBraze(payload);
15+
}
16+
17+
// Ensure analytics.user is defined
18+
if (window.analytics && window.analytics.user) {
19+
user.id = analytics.user().id();
20+
user.anonymousId = analytics.user().anonymousId();
21+
user.traits = analytics.user().traits();
22+
}
23+
24+
next(payload);
25+
};
26+
27+
function shouldSendToBraze(payload) {
28+
if (
29+
payload.userId() !== user.id ||
30+
payload.anonymousId() !== user.anonymousId
31+
) {
32+
return true;
33+
}
34+
35+
const traits = payload.traits();
36+
delete traits.id;
37+
38+
return JSON.stringify(user.traits) !== JSON.stringify(traits);
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@segment/analytics.js-middleware-braze-deduplicate",
3+
"description": "A braze middleware to deduplicate traits.",
4+
"version": "0.1.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-middleware",
8+
"segment",
9+
"braze"
10+
],
11+
"main": "lib/index.js",
12+
"author": "Segment <[email protected]>",
13+
"license": "SEE LICENSE IN LICENSE",
14+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/boomtrain#readme",
15+
"bugs": {
16+
"url": "https://github.com/segmentio/analytics.js-integrations/issues"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/segmentio/analytics.js-integrations.git"
21+
},
22+
"dependencies": {},
23+
"devDependencies": {}
24+
}

0 commit comments

Comments
 (0)