Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tealium / Personalize via Eventbridge integration #383

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9b7d4c4
Lambda event handler for events
manbearshark Mar 17, 2022
ca9fd14
tealium cf template
manbearshark Mar 17, 2022
d40848b
tealium event rules
manbearshark Mar 17, 2022
2d6d69e
update to rules for deployment
manbearshark Mar 17, 2022
ee1f76f
added tealium tracking code to index.html
manbearshark Jul 26, 2022
46371d2
added tealium env params and templates
manbearshark Jul 26, 2022
850aa9f
add option to exclude tealium deps
manbearshark Jul 27, 2022
81aa1e7
file naming issue fix
manbearshark Jul 27, 2022
a66f44a
fixed uid param
manbearshark Jul 27, 2022
8797915
commented out eventbus and eventsource
manbearshark Jul 27, 2022
d945428
set web ui parameters for tealium
manbearshark Jul 27, 2022
9c26cba
removed parameter passing for tealium ssm params
manbearshark Jul 28, 2022
2383bca
organize and re-label CDP integrations
manbearshark Jul 31, 2022
f6d7914
removed tealium vars from deploy
manbearshark Aug 1, 2022
01fc983
added source id variable + new script params
manbearshark Aug 2, 2022
15467cb
moved tealium script to body
manbearshark Aug 2, 2022
de8363d
added back load script
manbearshark Aug 2, 2022
065000a
string replacement syntax
manbearshark Aug 2, 2022
e790372
added back teal script load
manbearshark Aug 2, 2022
774913e
testing utag to see if it works
manbearshark Aug 3, 2022
1b8c14f
back to tealium.js
manbearshark Aug 5, 2022
5036872
revert to load utag.js per tealium support recs
manbearshark Aug 5, 2022
671f6b0
added track call for add to cart
manbearshark Aug 5, 2022
17c9705
added teal lambda code - update to add to cart
manbearshark Sep 7, 2022
211731d
trying a different event name
manbearshark Sep 7, 2022
9d1ffc3
added second event name property
manbearshark Sep 7, 2022
ecf3cbf
updated personalize lambda
manbearshark Sep 7, 2022
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
18 changes: 18 additions & 0 deletions aws/cloudformation-templates/base/_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ Parameters:
Description: Segment source write key (optional).
NoEcho: true

TealiumAccount:
Type: String
Description: Tealium account name
NoEcho: true

TealiumProfile:
Type: String
Description: Tealium profile name
NoEcho: true

TealiumSourceID:
Type: String
Description: Tealium source ID
NoEcho: true

mParticleOrgId:
Type: String
Description: mParticle Org Id
Expand Down Expand Up @@ -271,6 +286,9 @@ Resources:
AmplitudeApiKey: !Ref AmplitudeApiKey
OptimizelySdkKey: !Ref OptimizelySdkKey
SegmentWriteKey: !Ref SegmentWriteKey
TealiumAccount: !Ref TealiumAccount
TealiumProfile: !Ref TealiumProfile
TealiumSourceID: !Ref TealiumSourceID
mParticleOrgId: !Ref mParticleOrgId
mParticleApiKey: !Ref mParticleApiKey
mParticleSecretKey: !Ref mParticleSecretKey
Expand Down
45 changes: 45 additions & 0 deletions aws/cloudformation-templates/base/ssm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ Parameters:
Description: Write key for the Segment source used to gather real-time events (optional).
NoEcho: true

TealiumAccount:
Type: String
Description: Name of the Tealium account used for this deployment.
NoEcho: true

TealiumProfile:
Type: String
Description: Name of the Tealium profile used for this deployment.
NoEcho: true

TealiumSourceID:
Type: String
Description: Name of the source ID
NoEcho: true

mParticleOrgId:
Type: String
Description: mParticle Org ID from your mParticle workspace.
Expand Down Expand Up @@ -65,6 +80,12 @@ Conditions:
!Not [!Equals [!Ref OptimizelySdkKey, ""]]
HasSegmentWriteKey:
!Not [!Equals [!Ref SegmentWriteKey, ""]]
HasTealiumAccount:
!Not [!Equals [!Ref TealiumAccount, ""]]
HasTealiumProfile:
!Not [!Equals [!Ref TealiumProfile, ""]]
HasTealiumSourceID:
!Not [!Equals [!Ref TealiumSourceID, ""]]
HasmParticleOrgId:
!Not [!Equals [!Ref mParticleOrgId, ""]]
HasmParticleApiKey:
Expand Down Expand Up @@ -209,6 +230,30 @@ Resources:
Value: !If [HasSegmentWriteKey, !Ref SegmentWriteKey, "NONE"]
Description: "Retail Demo Store Segment source write key"

ParameterTealiumAccount:
Type: "AWS::SSM::Parameter"
Properties:
Name: "/retaildemostore/webui/tealium_account"
Type: "String"
Value: !If [HasTealiumAccount, !Ref TealiumAccount, "NONE"]
Description: "Retail Demo Store Tealium account name"

ParameterTealiumProfile:
Type: "AWS::SSM::Parameter"
Properties:
Name: "/retaildemostore/webui/tealium_profile"
Type: "String"
Value: !If [HasTealiumProfile, !Ref TealiumProfile, "NONE"]
Description: "Retail Demo Store Tealium profile name"

ParameterTealiumSourceID:
Type: "AWS::SSM::Parameter"
Properties:
Name: "/retaildemostore/webui/tealium_source_id"
Type: "String"
Value: !If [HasTealiumSourceID, !Ref TealiumSourceID, "NONE"]
Description: "Retail Demo Store Tealium source ID"

ParametermParticleOrgId:
Type: "AWS::SSM::Parameter"
Properties:
Expand Down
119 changes: 119 additions & 0 deletions aws/cloudformation-templates/tealium.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
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: /
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: '*'

# tealiumLiveEventBus:
# Type: AWS::Events::EventBus
# Properties:
# EventSourceName: !Sub 'aws.partner/tealium.com/${AWS:AccountId}-tealium-event-source'
# Name: "Tealium live events source"

# tealiumEventRule:
# Type: AWS::Events::Rule
# Properties:
# Description: "Handles Tealium events."
# EventBusName: tealiumLiveEventBus
# EventPattern:
# detail-type:
# - transaction
# State: "ENABLED"
# Targets:
# -
# Arn:
# Fn::GetAtt:
# - "tealiumPersonalizeLambda"
# - "Arn"

# 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.
Value: !GetAtt tealiumPersonalizeLambda.Arn
67 changes: 61 additions & 6 deletions aws/cloudformation-templates/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Metadata:
- DeployLocationServices
- DeployPersonalizedOffersCampaign
- Label:
default: "Amazon Pay (optional)"
default: "Amazon Pay (Optional)"
Parameters:
- AmazonPayStoreId
- AmazonPayMerchantId
Expand All @@ -56,21 +56,28 @@ Metadata:
- AlexaSkillId
- AlexaAmazonPayDefaultSandboxEmail
- Label:
default: "Optional Integrations"
default: "Customer Data Platform (CDP) Integrations (Optional)"
Parameters:
- AmplitudeApiKey
- OptimizelySdkKey
- IncludeSegmentDependencies
- SegmentWriteKey
- IncludemParticleDependencies
- mParticleOrgId
- mParticleApiKey
- mParticleSecretKey
- mParticleS2SApiKey
- mParticleS2SSecretKey
- IncludeSegmentDependencies
- SegmentWriteKey
- IncludeTealiumDependencies
- TealiumAccount
- TealiumProfile
- TealiumSourceID
- Label:
default: "Measurement Integrations (Optional)"
Parameters:
- GoogleAnalyticsMeasurementId
- OptimizelySdkKey
- Label:
default: "Fenix Commerce EDD Integration"
default: "Fenix Commerce EDD Integration (Optional)"
Parameters:
- FenixZipDetectUrl
- FenixTenantId
Expand Down Expand Up @@ -135,6 +142,12 @@ Metadata:
default: "Deploy Segment Resources"
SegmentWriteKey:
default: "Segment Write Key"
TealiumAccount:
default: "Tealium account name"
TealiumProfile:
default: "Tealium account profile"
TealiumSourceID:
default: "Tealium source key"
IncludemParticleDependencies:
default: "Deploy mParticle Resources"
mParticleOrgId:
Expand Down Expand Up @@ -372,6 +385,30 @@ Parameters:
Segment write key for real-time data collection (optional). Be sure the Segment resources are deployed (above) if you specify a write key.
NoEcho: true

IncludeTealiumDependencies:
Type: String
Description: >
Whether to deploy the resources required for the Tealium workshops.
AllowedValues:
- 'Yes'
- 'No'
Default: 'No'

TealiumAccount:
Type: String
Description: >
Tealium account name from your Tealium IQ console

TealiumProfile:
Type: String
Description: >
Tealium account profile name from your Tealium IQ console.

TealiumSourceID:
Type: String
Description: >
Tealium source key for the web UI from your Tealium IQ console.

IncludemParticleDependencies:
Type: String
Description: >
Expand Down Expand Up @@ -474,6 +511,10 @@ Conditions:
- !Ref IncludeSegmentDependencies
- "Yes"

DeployTealiumResources: !Equals
- !Ref IncludeTealiumDependencies
- "Yes"

DeploymParticleResources: !Equals
- !Ref IncludemParticleDependencies
- 'Yes'
Expand Down Expand Up @@ -508,6 +549,9 @@ Resources:
ParentStackName: !Ref AWS::StackName
OptimizelySdkKey: !Ref OptimizelySdkKey
SegmentWriteKey: !Ref SegmentWriteKey
TealiumAccount: !Ref TealiumAccount
TealiumProfile: !Ref TealiumProfile
TealiumSourceID: !Ref TealiumSourceID
mParticleOrgId: !Ref mParticleOrgId
mParticleApiKey: !Ref mParticleApiKey
mParticleSecretKey: !Ref mParticleSecretKey
Expand Down Expand Up @@ -771,6 +815,17 @@ Resources:
ResourceBucket: !Ref ResourceBucket
ResourceBucketRelativePath: !Ref ResourceBucketRelativePath

# Tealium workshop resources
TealiumPersonalize:
Condition: DeployTealiumResources
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub https://s3.amazonaws.com/${ResourceBucket}/${ResourceBucketRelativePath}cloudformation-templates/tealium.yaml
Parameters:
ResourceBucket: !Ref ResourceBucket
ResourceBucketRelativePath: !Ref ResourceBucketRelativePath
Uid: !Sub ${AWS::StackName}-${AWS::Region}

# mParticle Lambda Functions Kinesis and Roles
mParticlePersonalize:
Condition: DeploymParticleResources
Expand Down
17 changes: 17 additions & 0 deletions src/aws-lambda/tealium-eventbridge-personalize/bundle.sh
Original file line number Diff line number Diff line change
@@ -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!"
13 changes: 13 additions & 0 deletions src/aws-lambda/tealium-eventbridge-personalize/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/aws-lambda/tealium-eventbridge-personalize/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "tealium-eventbridge-personalize",
"version": "1.0.0",
"description": "tealium eventbridge to personalize integration example",
"main": "tealium-personalize.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Loading