Sentimentanalyse op X
Op deze pagina
Begrijp wat uw publiek echt denkt
Sentimentanalyse transformeert duizenden berichten in een helder beeld van hoe uw merk, concurrenten of branche worden waargenomen. Met X Search en de redeneercapaciteiten van Grok gaat u verder dan een simpele positief/negatief-indeling. U doorgrondt emotionele nuances, latente frustraties en waarschuwingssignalen.
Sentimentdimensies in marketing
Sentimentanalyse in marketing gaat verder dan de binaire indeling positief/negatief. Dit zijn de relevante dimensies:
Schaal met 5 sentimentniveaus
- Zeer positief: enthousiasme, actieve aanbeveling, merkliefde
- Positief: tevredenheid, goedkeuring, interesse
- Neutraal: feitelijke vermelding, delen van informatie
- Negatief: teleurstelling, kritiek, frustratie
- Zeer negatief: woede, oproep tot boycot, crisis
Aanvullende dimensies
- Koopintentie: Geeft het bericht blijk van de intentie om te kopen of op te zeggen?
- Invloed: Komt het bericht van een invloedrijk account of van een gemiddelde consument?
- Viraliteit: Heeft het bericht potentieel om zich te verspreiden?
- Urgentie: Vereist het signaal een snelle reactie?
Sentiment analyseren met X Search en Grok
Sentimentanalyse voor uw merk
def analyser_sentiment_marque(marque, periode_jours=7):
from datetime import datetime, timedelta
today = datetime.now().strftime("%Y-%m-%d")
start = (datetime.now() - timedelta(days=periode_jours)).strftime("%Y-%m-%d")
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input=f"""Analyze the sentiment of conversations on X
about {marque} between {start} and {today}.
For each conversation theme identified, provide:
1. The theme (e.g., "customer service", "product quality")
2. The dominant sentiment (1-5 scale)
3. The estimated conversation volume
4. The most representative verbatims
5. The most influential accounts in the discussion
6. Sentiment evolution over the period
Final summary:
- Global sentiment score (1-5)
- Top 3 positive points
- Top 3 negative points
- Any alerts""",
tools=[{
"type": "x_search",
"from_date": start,
"to_date": today
}]
)
return response.output_text
Vergelijkende sentimentanalyse
Vergelijk de perceptie van uw merk met die van uw concurrenten:
def sentiment_comparatif(marques, periode_jours=30):
from datetime import datetime, timedelta
today = datetime.now().strftime("%Y-%m-%d")
start = (datetime.now() - timedelta(days=periode_jours)).strftime("%Y-%m-%d")
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input=f"""Compare sentiment on X for these brands:
{', '.join(marques)}
Period: {start} to {today}
For each brand, evaluate:
- Global sentiment score (1-5, with decimal)
- Dominant positive themes
- Dominant negative themes
- Strengths perceived by the public
- Weaknesses perceived by the public
Final comparison table ranked by sentiment.
Identify positioning opportunities for the
first brand in the list.""",
tools=[{"type": "x_search", "from_date": start, "to_date": today}]
)
return response.output_text
Gestructureerde resultaten in JSON verkrijgen
Vraag een JSON-output aan om sentimentanalyse in een datapipeline te integreren:
def sentiment_structure(marque, periode_jours=7):
from datetime import datetime, timedelta
today = datetime.now().strftime("%Y-%m-%d")
start = (datetime.now() - timedelta(days=periode_jours)).strftime("%Y-%m-%d")
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input=f"""Analyze sentiment on X about {marque}.
Period: {start} to {today}.
Respond ONLY in valid JSON with this structure:
{{
"brand": "{marque}",
"period": "{start} - {today}",
"global_score": 3.7,
"distribution": {{
"very_positive": 15,
"positive": 35,
"neutral": 30,
"negative": 15,
"very_negative": 5
}},
"themes": [
{{
"name": "customer service",
"score": 2.1,
"volume": "high",
"trend": "stable"
}}
],
"alerts": ["alert description if applicable"],
"recommendations": ["recommended action"]
}}""",
tools=[{"type": "x_search", "from_date": start, "to_date": today}]
)
return response.output_text
De evolutie van sentiment in de tijd volgen
Een eenmalige analyse is nuttig, maar het volgen van de evolutie in de tijd onthult trends. Vergelijk resultaten week na week:
def evolution_sentiment(marque, nb_semaines=4):
from datetime import datetime, timedelta
import json
historique = []
for i in range(nb_semaines, 0, -1):
end = (datetime.now() - timedelta(weeks=i-1)).strftime("%Y-%m-%d")
start = (datetime.now() - timedelta(weeks=i)).strftime("%Y-%m-%d")
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input=f"""Sentiment score on X for {marque}
from {start} to {end}.
Respond with a JSON: {{"week": "{start}",
"score": X.X, "volume": N, "dominant_theme": "..."}}""",
tools=[{
"type": "x_search",
"from_date": start,
"to_date": end
}]
)
historique.append(response.output_text)
return historique
Reputatiecrises detecteren
Sentimentanalyse is uw eerste alarmsysteem bij een crisis:
def detecter_crise(marque, seuil_negatif=40):
resultat = sentiment_structure(marque, periode_jours=1)
# Parse the JSON
import json
data = json.loads(resultat)
pct_negatif = (data["distribution"]["negative"] +
data["distribution"]["very_negative"])
if pct_negatif > seuil_negatif:
return {
"alert": True,
"level": "CRITICAL" if pct_negatif > 60 else "IMPORTANT",
"score": data["global_score"],
"negative_themes": [t for t in data["themes"] if t["score"] < 2.5],
"recommendation": "Crisis meeting recommended"
}
return {"alert": False, "score": data["global_score"]}
Belangrijkste punten
- Sentimentanalyse gaat verder dan positief/negatief: evalueer intentie, invloed en urgentie
- Gebruik een schaal met 5 niveaus om nuances vast te leggen
- Vraag gestructureerde JSON-outputs aan om uw dashboards te voeden
- Volg de evolutie van sentiment in de tijd, niet alleen momentopnamen
- Vergelijk uw sentiment systematisch met dat van uw concurrenten
- Stel drempelwaarden voor waarschuwingen in om reputatiecrises in een vroeg stadium te detecteren