Practical Guide to E-commerce Ad Creatives: Real-Time A/B Testing with API Data

Core Objectives

  • Automatically generate multiple versions of short video ad copy (titles, hooks, voiceover scripts, etc.)

  • Quickly push different versions to TikTok/Douyin and monitor their performance

  • Achieve full automation of the A/B testing process from creation to iteration

  • Dynamically adjust creative content based on hot comment keywords and product selling points

1. Input Sources: Comment Keywords + Product Detail API

Step 1: Extract Hot Keywords from TikTok Video Comments

Retrieve user comment data for a given TikTok video and perform keyword extraction to identify frequently mentioned topics, which can guide creative copywriting.

import requests

from collections import Counter

def get_tiktok_comments(video_id):

url = "https://luckdata.io/api/tiktok-api/comment_list_by_video"

params = {"video_id": video_id}

res = requests.get(url, params=params)

return res.json()

def extract_keywords(comments):

keywords = []

for c in comments['data']:

text = c.get("text", "")

for word in text.split(): # Replace with jieba or Spacy for better tokenization

if len(word) > 1:

keywords.append(word.lower())

return Counter(keywords).most_common(10)

comment_data = get_tiktok_comments("7349338458284xxxxxx")

hot_keywords = extract_keywords(comment_data)

print(hot_keywords)

Step 2: Fetch Product Details (Lazada Example)

Use API to retrieve product title and key selling points from e-commerce platforms, which will be used for generating ad content.

def get_lazada_product_detail():

url = "https://luckdata.io/api/lazada-online-api/x3fmgkg9arn3"

params = {"site": "vn", "itemId": "2396338609"}

res = requests.get(url, params=params)

return res.json()

product_detail = get_lazada_product_detail()

print(product_detail["data"]["title"])

2. Generating Creative Versions (Prompt + LLM)

Prompt Structure

Combine extracted comment keywords and product titles to design prompts that guide LLMs in generating engaging ad titles and hook lines.

import openai

def generate_hooks(keywords, product_title):

prompt = f"""

You are a short video ad copy expert. Based on the following inputs, generate creative content:

Product Title: {product_title}

Hot Keywords: {', '.join([kw for kw, _ in keywords])}

Please output:

1. Three engaging ad titles suitable for TikTok/Douyin

2. Three hook lines that can be delivered within the first 5 seconds of a video

"""

response = openai.ChatCompletion.create(

model="gpt-4",

messages=[{"role": "user", "content": prompt}]

)

return response['choices'][0]['message']['content']

hooks = generate_hooks(hot_keywords, product_detail["data"]["title"])

print(hooks)

3. A/B Testing Execution: Upload + Performance Monitoring

✅ Auto Publishing Versions with Metadata Tracking

Use third-party tools or TikTok's business API to publish multiple video versions, combining different titles and hooks, such as:

  • Title A + Hook A

  • Title A + Hook B

  • Title B + Hook A

  • Title B + Hook B

Record metadata like version ID, upload time, and associated creative assets for each variant.

✅ Monitoring Performance via TikTok Video Stats API

Retrieve performance metrics for each video version including plays, likes, comments, and shares.

def get_tiktok_video_stats(video_id):

url = "https://luckdata.io/api/tiktok-api/tiktok_video_info"

params = {"video_id": video_id}

res = requests.get(url, params=params)

return res.json()

video_stats = get_tiktok_video_stats("7349338458284xxxxxx")

print(video_stats)

Key data fields include:

  • play_count

  • like_count

  • share_count

  • comment_count

4. A/B Test Metrics and Optimization Strategy

KPI Logic and Performance Scoring

Evaluate each version using a combination of metrics such as play count, like rate, completion rate, and order conversions.

Version ID

Play Count

Like Rate

Completion Rate

Orders (E-com)

ROI Estimate

A1

10,000

3.2%

70%

87

High

A2

9,000

2.1%

64%

65

Medium

Composite indicators:

  • CTR = Like Count / Play Count

  • Completion Rate = Completed Views / Total Views (if available)

  • Conversion Rate = Orders / Views (based on tracked links)

5. Automated Iteration Based on Performance

Build an automated loop for creative optimization:

  • Automatically deactivate underperforming versions (e.g., CTR and conversions < 30% of average)

  • Extract new keywords from recent comments to generate fresh creatives

  • Reupload and re-enter the A/B testing cycle

This creates a full feedback loop: Auto-generation → Publishing → Data Feedback → Creative Optimization

✅ Summary: Components Required for Full A/B Testing Loop

Component

Implementation Method

Comment Keyword Extraction

TikTok/Douyin API + NLP Tools

Product Info Collection

E-commerce API (e.g., Lazada)

Creative Generation

LLM (e.g., ChatGPT) with Prompt Design

Data Collection & Analysis

TikTok API for performance metrics

Feedback & Decision Logic

Automated rules based on KPI thresholds

Articles related to APIs :