Businesses in ecommerce have the challenge of measuring their ad-to-order conversion ratio for ads or promotional campaigns displayed on a webpage. Tracking the number of users that clicked on a particular promotional ad and the number of users who actually added items to their cart or placed an order helps measure the ad’s effectiveness. Utilizing promotional ads that have higher conversion rates enables you to effectively utilize limited space on your ecommerce websites and applications.
This post demonstrates how to sessionize and aggregate clickstream and order data, compute the conversion ratio in real time, and generate data visualizations. We use Amazon Kinesis Data Streams to ingest and send data to Amazon Simple Storage Service (Amazon S3), and AWS Glue, Amazon Athena, and Amazon QuickSight to catalog, analyze, and visualize the data, respectively.
To measure ad-to-order conversion, you need two important pieces of data: user clicks and orders. Clickstream data is captured as users navigate through the site, each time users click on the webpage, and the metadata associated with those clicks. Depending on the user base and number of active users at any moment, clickstream data can be a large amount of data generated per second. Typically, every ecommerce system has a centralized order management system that captures orders created from different channels like a web portal or mobile app. To compute an ad-to-order conversion rate, you join clickstream data and order data over time: (total number of orders/total number of clicks) *100.
The following diagram illustrates the architecture of our solution.
The solution has six main categories.
- Data generators – Clickstream and order data is generated with the help of an AWS Lambda function. The function is triggered by a scheduled Amazon CloudWatch Events event every minute and generates random clicks for ingestion into a Kinesis data stream. Similarly, another function triggered by a CloudWatch event generates random orders for ingestion into a second data stream. In a production environment, this data comes from clickstream generators and a centralized order management system.
- Data ingestion – Kinesis data streams ingest clickstream and order data as they are generated.
- Data sessionization – Data sessionization helps group related data. For clickstream data, we can group clicks on an ad by different users or time periods. For order data, we can group orders by different ads. We use Amazon Kinesis Data Analytics for SQL to analyze streaming data in real time with standard SQL. Sessionized clickstream and order data is ingested into another in-application stream.
- Data processing and storage – The sessionization stream from Kinesis Data Analytics for SQL is ingested into an Amazon Kinesis Data Firehose delivery stream, which delivers the data to a pre-configured S3 bucket.
- Data Catalog – You use AWS Glue to crawl the clickstream and orders data in their respective S3 buckets, as well as build metadata definitions and tables in Athena. AWS Glue crawlers run every hour to update table definitions, and Athena views are built to compute the ad-to-order conversion.
- Data visualization – You use QuickSight to generate visualizations.
Before getting started, you must provision your resources with AWS CloudFormation.
- Choose Launch Stack.
- Choose Next.
- For Stack name, enter a name for the stack.
- For Bucket Name for Clicks, enter the name of the S3 bucket that holds clickstream data (for this post,
- For Bucket Name for Orders, enter the name of the S3 bucket that holds order data (
- Enter any tags you wish to assign to the stack.
- Choose Next.
- Verify that the stack has been created successfully.
If you have never used QuickSight in this account before, sign up for QuickSight before moving on to the next step. Keep in mind that admin access to the Enterprise Edition QuickSight instance is needed to complete setup.
Generating and ingesting clickstream data
On the Lambda console, view your function
ingest-clickstream for ingesting clickstream data. The clickstream data attributes include
Timestamp. The event contains promotional ad information on the webpage clicked by the user. This function generates random clickstreams and ingests it into the data stream
ClickStream. The following screenshot shows your function details on the console.
A CloudWatch Events rule invokes this function every minute. The following screenshot shows sample data that was ingested into the data stream.
The Event column represents the portion of the webpage the user clicked; every click on the webpage has a unique ID and type assigned (for example,
P601 has the event type
Promotion, C301 has the event type
Generating and ingesting order data
On the AWS Lambda console, view your function
ingest-order for ingesting order data. This function ingests random orders.
Each order has order lines, which contain the attributes
Quantity (see the following screenshot). The promotion attribute indicates the ad the user clicked before adding the item to their shopping cart. This function generates random orders and ingests it into
Promotion attribute joins clickstream data and order data.
Sessionizing the data
To sessionize the data, complete the following steps:
- On the Kinesis Data Analytics console, select
- Choose Run.
- Repeat the same step for
- When the status changes to Running, choose the application name.
- Under Real time analytics, choose Go to SQL results.
- Choose the Real-time analytics
The application groups clicks in 1-minute intervals. Let’s take the ad
P701 as an example. If this ad is clicked by multiple users, this SQL function adds all the clicks by different users in the last minute. If five users clicked on
P701 in the last minute, the function outputs a
ClickCount of 5. A stagger window is used because it’s well-suited for analyzing groups of data that arrive at inconsistent times.
- On the Kinesis Data Analytics console, choose OrderAnalysisApp.
- Choose Go to SQL results.
This application groups orders by
Promotion, as shown in the following screenshot.
Processing and storing the data
In the data processing and storage stage, aggregated clickstream and order data is delivered to a Kinesis Data Firehose delivery stream. Kinesis Data Firehose delivers clickstream aggregated records and orders to the
order-stream buckets, respectively. The data is partitioned by year, month, and day. The following screenshot shows the delivery streams on the console.
Analyzing the data
To analyze your data, complete the following steps:
- Verify that the S3 bucket was created for clickstream and orders.
The data in the bucket is partitioned by year, month, date, and hour.
- On the AWS Glue console, view the clickstream and orders crawlers.
These two crawlers crawl the
order-stream buckets every 15 minutes and create tables.
- To run the crawlers on demand, choose Run crawler.
When the crawler is finished, the
Tables added column displays 1.
- In the navigation pane, choose Tables.
- Verify that the crawlers created the tables.
- On the Athena console, choose Saved queries.
You can see three queries have been created.
- Select view_clicks_aggregate to load it in the query editor.
- Select ad_to_order_conversion and choose Run Query.
If the Amazon S3 bucket name has
-, the crawler replaces
_ while creating the table.
_in the table name when creating the view.
- Repeat the same process for
Make sure you run
view_orders_aggregate before running
- Choose view_conversion_ratio and choose Preview.
Orders and clicks for each promotion and the corresponding conversion ratio are displayed.
Visualizing the data
To visualize your data, you first load it into QuickSight. You can then create visualizations. In this section, we also configure a scheduled data refresh.
Loading the data
To visualize your data, you must first load your data into QuickSight.
- On the QuickSight console, from the Admin drop-down menu, choose Manage QuickSight.
- In the navigation pane, choose Security & Permissions.
- Choose Add or remove.
- Select Amazon Athena.
- Select Amazon S3 to edit QuickSight access to your S3 buckets.
- Choose the Details link next to Amazon S3.
- Choose Select S3 buckets.
- Select the bucket names you provided for clicks and orders.
- Choose Finish.
- Choose Update.
- Choose the QuickSight icon on the top left of the admin panel to proceed back to the home screen.
- In the navigation pane, choose Datasets.
- Choose New dataset.
- Choose Athena.
- For Data source name, enter
- Choose Validate Connection.
- After your connection is validated, choose Create data source.
- For Database, choose ad-to-order-conversion.
- For Tables, select view_conversion_ratio.
- Choose Select.
- Choose Visualize.
In this section, we create two visualizations of our data. We first make a horizontal bar chart.
- From the Add menu, choose Add Calculated Field.
- Enter the formula
- Choose Save.
- Choose … next to Click to orders.
- For Show as, choose Percent.
- For Visual type, choose Horizontal bar chart.
- Drag promotion to Y-axis.
- Drag clicks_to_orders to Value.
- Drag date to Group/Color.
The following screenshot shows our visualization.
We now make our second visualization, a vertical bar chart.
- Choose the + icon next to Sheet1.
- For Visual types, choose Vertical bar chart.
- Drag promotions to Y-axis.
- Drag clicks and orders to Value.
This graph displays clicks and orders for each promotion.
- Choose Insights on the left panel to see a summary of your insights.
Refreshing the data
We can also set up a scheduled refresh for our data.
- Choose Manage Data.
- Choose view_conversion_ratio.
- Choose Schedule refresh.
- Choose Create.
- For Repeats, choose Hourly.
- Choose Create.
You see a confirmation message that you configured a refresh one time per hour.
In this post, we showed you how to use AWS analytics and storage services to address business challenges that require handling large volumes of data. Kinesis Data Streams and Kinesis Data Analytics let you ingest large volumes of data and sessionize the data. We also showed you how to analyze and visualize the clickstream and order data using AWS Glue, Athena, and QuickSight.
About the Authors
Gandhi Raketla is a Senior Solutions Architect for AWS. He works with AWS customers and partners on cloud adoption, architecting solutions that help customers foster agility and innovation.
Nick Sack is a DevOps Consultant for AWS Professional Services. He is passionate about working with customers and building automated solutions to help customers on their cloud journeys. When not working, Nick enjoys hiking, playing soccer, reading, and learning about technology.
Credit: Source link