From 9b7d4c40888b7a0c22be1a2134afc324c089a4b5 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 17 Mar 2022 12:49:26 -0700 Subject: [PATCH 01/27] Lambda event handler for events --- .../tealium-eventbridge-personalize/bundle.sh | 17 +++++++++++++++++ .../tealium-eventbridge-personalize/stage.sh | 16 ++++++++++++++++ .../tealium-personalize.js | 0 3 files changed, 33 insertions(+) create mode 100755 src/aws-lambda/tealium-eventbridge-personalize/bundle.sh create mode 100755 src/aws-lambda/tealium-eventbridge-personalize/stage.sh create mode 100644 src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js diff --git a/src/aws-lambda/tealium-eventbridge-personalize/bundle.sh b/src/aws-lambda/tealium-eventbridge-personalize/bundle.sh new file mode 100755 index 000000000..a7b7abcdd --- /dev/null +++ b/src/aws-lambda/tealium-eventbridge-personalize/bundle.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +LAMBDA_SOURCE=tealium-personalize.js +PACKAGE_FILE=tealium-personalize.zip + +echo "Cleaning up intermediate files" +[ -e ${PACKAGE_FILE} ] && rm ${PACKAGE_FILE} +[ -e "package" ] && rm -rf package +[ -e "node_modules" ] && rm -rf node_modules + +npm ci + +echo "Adding Lambda function source code to package" +zip -gr ${PACKAGE_FILE} ${LAMBDA_SOURCE} package.json node_modules + +echo "Done!" \ No newline at end of file diff --git a/src/aws-lambda/tealium-eventbridge-personalize/stage.sh b/src/aws-lambda/tealium-eventbridge-personalize/stage.sh new file mode 100755 index 000000000..511d6fc58 --- /dev/null +++ b/src/aws-lambda/tealium-eventbridge-personalize/stage.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +S3_BUCKET=$1 +#Path with trailing / +S3_PATH=$2 + +if [ "${S3_BUCKET}" == "" ]; then + echo "Usage: $0 S3_BUCKET [S3_PATH]" + echo " where S3_BUCKET is the S3 bucket to upload resources to and S3_PATH is optional path but if specified must have a trailing '/'" + exit 1 +fi + +source ./bundle.sh + +echo "Staging bundle to S3" +aws s3 cp ${PACKAGE_FILE} s3://${S3_BUCKET}/${S3_PATH}aws-lambda/${PACKAGE_FILE} $S3PUBLIC \ No newline at end of file diff --git a/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js b/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js new file mode 100644 index 000000000..e69de29bb From ca9fd14ab81002681a65fe91f5437280d4e264b0 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 17 Mar 2022 14:00:37 -0700 Subject: [PATCH 02/27] tealium cf template --- aws/cloudformation-templates/tealium.yml | 87 +++++++++++++++++++ .../tealium-personalize.js | 21 +++++ 2 files changed, 108 insertions(+) create mode 100644 aws/cloudformation-templates/tealium.yml diff --git a/aws/cloudformation-templates/tealium.yml b/aws/cloudformation-templates/tealium.yml new file mode 100644 index 000000000..e8108b6e9 --- /dev/null +++ b/aws/cloudformation-templates/tealium.yml @@ -0,0 +1,87 @@ +--- +AWSTemplateFormatVersion: 2010-09-09 + +Description: > + This template deploys a Lambda that can process events from a Tealium Event Bridge event. There is also a rule that + specifies the event types that this will accept from Tealium + +Parameters: + ResourceBucket: + Type: String + Description: > + S3 bucket name where the Retail Demo Store deployment resources are staged (product images, nested CloudFormation templates, source code snapshot, + notebooks, deployment Lambda code, etc). You can substitute your own bucket here if needed. + + ResourceBucketRelativePath: + Type: String + Description: > + Optional path in the Deployment Resources Staging bucket where the deployment resources are stored (e.g. path/path2/). + Leave blank if resources are at the root of the Staging Resource Bucket. If specified, MUST end with '/'. + + Uid: + Type: String + Description: > + Uid generated from the root template to provide unique resource names + +Resources: + + tealiumPersonalizeLambda: + Type: 'AWS::Lambda::Function' + Properties: + Description: 'Handles events from Tealium over Event Bridge and passes them to the specified Personalize solution.' + Handler: tealium-personalize.tealiumPersonalizeEventHandler + Role: !GetAtt + - tealiumPersonalizeLambdaExecutionRole + - Arn + Code: + S3Bucket: !Ref ResourceBucket + S3Key: !Sub '${ResourceBucketRelativePath}aws-lambda/tealium-personalize.zip' + Runtime: nodejs12.x + Timeout: 900 + FunctionName: !Sub '${Uid}-tealiumPersonalizeLambda' + + tealiumPersonalizeLambdaExecutionRole: + Type: 'AWS::IAM::Role' + Properties: + Description: 'Execution role for the Lambda provided with the tealium workshop.' + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: + - 'sts:AssumeRole' + Path: / + ManagedPolicyArns: + - 'arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole' + Policies: + - PolicyName: root + PolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Action: + - logs:CreateLogStream + - logs:PutLogEvents + Resource: + - !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${Uid}-tealiumPersonalizeLambda*:log-stream:*' + - !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${Uid}-tealiumPersonalizeLambda*' + - Effect: Allow + Action: + - ssm:GetParameter + - ssm:GetParameters + Resource: + - !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/retaildemostore*' + - Effect: Allow + Action: + - logs:CreateLogGroup + - personalize:GetRecommendations + - personalize:PutEvents + Resource: '*' + +Outputs: + tealiumPersonalizeLambdaArn: + Description: Lambda function ARN for the tealium Personalize Lambda function. + Value: !GetAtt tealiumPersonalizeLambda.Arn diff --git a/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js b/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js index e69de29bb..5eaddef32 100644 --- a/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js +++ b/src/aws-lambda/tealium-eventbridge-personalize/tealium-personalize.js @@ -0,0 +1,21 @@ +/* + Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this + software and associated documentation files (the "Software"), to deal in the Software + without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +// The consuming service (target) Lambda functions + +exports.tealiumPersonalizeEventHandler = async (event) => { + console.log('--- Telaium Event ---') + console.log(JSON.stringify(event, null, 2)) +} \ No newline at end of file From d40848b530b29a0e9029729013abcd0180b99d34 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 17 Mar 2022 14:51:16 -0700 Subject: [PATCH 03/27] tealium event rules --- aws/cloudformation-templates/tealium.yml | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/aws/cloudformation-templates/tealium.yml b/aws/cloudformation-templates/tealium.yml index e8108b6e9..b0cb315bc 100644 --- a/aws/cloudformation-templates/tealium.yml +++ b/aws/cloudformation-templates/tealium.yml @@ -54,8 +54,6 @@ Resources: Action: - 'sts:AssumeRole' Path: / - ManagedPolicyArns: - - 'arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole' Policies: - PolicyName: root PolicyDocument: @@ -81,6 +79,35 @@ Resources: - personalize:PutEvents Resource: '*' + tealiumEventRule: + Type: AWS::Events::Rule + Properties: + Description: "Example event rule to handle Tealium events" + EventBusName: "tealiumLiveEventBus" + EventPattern: + detail-type: + - transaction + State: "ENABLED" + Targets: + - + Arn: + Fn::GetAtt: + - "tealiumPersonalizeLambda" + - "Arn" + Id: "atmConsumerTarget1" + + PermissionForEventsToInvokeLambda: + Type: AWS::Lambda::Permission + Properties: + FunctionName: + Ref: "tealiumPersonalizeLambda" + Action: "lambda:InvokeFunction" + Principal: "events.amazonaws.com" + SourceArn: + Fn::GetAtt: + - "tealiumEventRule" + - "Arn" + Outputs: tealiumPersonalizeLambdaArn: Description: Lambda function ARN for the tealium Personalize Lambda function. From 2d6d69e5cc88478b99d10de1e9771d83ef78d97c Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 17 Mar 2022 14:54:04 -0700 Subject: [PATCH 04/27] update to rules for deployment --- aws/cloudformation-templates/tealium.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/cloudformation-templates/tealium.yml b/aws/cloudformation-templates/tealium.yml index b0cb315bc..4aad1e2ff 100644 --- a/aws/cloudformation-templates/tealium.yml +++ b/aws/cloudformation-templates/tealium.yml @@ -94,7 +94,6 @@ Resources: Fn::GetAtt: - "tealiumPersonalizeLambda" - "Arn" - Id: "atmConsumerTarget1" PermissionForEventsToInvokeLambda: Type: AWS::Lambda::Permission From ee1f76feeb8b42c91fe9f7e7283a90d2c4c993c4 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 26 Jul 2022 14:03:58 -0700 Subject: [PATCH 05/27] added tealium tracking code to index.html --- src/web-ui/public/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/web-ui/public/index.html b/src/web-ui/public/index.html index cb39c102a..5ae0fd635 100644 --- a/src/web-ui/public/index.html +++ b/src/web-ui/public/index.html @@ -15,6 +15,8 @@ <%= VUE_APP_LAYER0_ENABLED === 'true' ? ``: '' %> <%= VUE_APP_SEGMENT_WRITE_KEY === 'NONE' ? '' : ``: '' %> <%= VUE_APP_SEGMENT_WRITE_KEY === 'NONE' ? '' : ` - + + + + <%= VUE_APP_TEALIUM_ACCOUNT === 'NONE' && VUE_APP_TEALIUM_PROFILE === 'NONE' && VUE_APP_TEALIUM_SOURCE_ID === 'NONE' ? '' : '' %> diff --git a/src/web-ui/src/analytics/AnalyticsHandler.js b/src/web-ui/src/analytics/AnalyticsHandler.js index e668d02ff..ac5fed805 100644 --- a/src/web-ui/src/analytics/AnalyticsHandler.js +++ b/src/web-ui/src/analytics/AnalyticsHandler.js @@ -1012,6 +1012,10 @@ export const AnalyticsHandler = { window.analytics.track('Search', eventProperties); } + if (this.tealiumEnabled()) { + window.tealium.track('Search', eventProperties); + } + if (this.mParticleEnabled()) { let customAttributes = { resultCount: numResults, From de8363d9b373a39717d350a15f83d6fa08bc7aad Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 2 Aug 2022 11:16:07 -0700 Subject: [PATCH 17/27] added back load script --- src/web-ui/public/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/web-ui/public/index.html b/src/web-ui/public/index.html index e23e434b8..382b5d614 100644 --- a/src/web-ui/public/index.html +++ b/src/web-ui/public/index.html @@ -27,6 +27,7 @@ - <%= VUE_APP_TEALIUM_ACCOUNT === 'NONE' && VUE_APP_TEALIUM_PROFILE === 'NONE' && VUE_APP_TEALIUM_SOURCE_ID === 'NONE' ? '' : '' %> + <%= VUE_APP_TEALIUM_ACCOUNT === 'NONE' && VUE_APP_TEALIUM_PROFILE === 'NONE' && VUE_APP_TEALIUM_SOURCE_ID === 'NONE' ? '' : + ' + + <%= VUE_APP_TEALIUM_ACCOUNT === 'NONE' && VUE_APP_TEALIUM_PROFILE === 'NONE' && VUE_APP_TEALIUM_SOURCE_ID === 'NONE' ? '' : ` - - - <%= VUE_APP_TEALIUM_ACCOUNT === 'NONE' && VUE_APP_TEALIUM_PROFILE === 'NONE' && VUE_APP_TEALIUM_SOURCE_ID === 'NONE' ? '' : - `