Analisi del sentiment su X
In questa pagina
Comprendi cosa pensa davvero il tuo pubblico
L’analisi del sentiment trasforma migliaia di post in una lettura chiara di come vengono percepiti il tuo brand, i concorrenti o il settore. Con X Search e le capacità di ragionamento di Grok, puoi andare oltre la semplice classificazione positivo/negativo per comprendere le sfumature emotive, le frustrazioni latenti e i segnali di allarme.
Dimensioni del sentiment nel marketing
L’analisi del sentiment nel marketing va oltre il binario positivo/negativo. Ecco le dimensioni rilevanti:
Scala del sentiment a 5 livelli
- Molto positivo: entusiasmo, raccomandazione attiva, amore per il brand
- Positivo: soddisfazione, approvazione, interesse
- Neutro: menzione fattuale, condivisione di informazioni
- Negativo: delusione, critica, frustrazione
- Molto negativo: rabbia, invito al boicottaggio, crisi
Dimensioni aggiuntive
- Intenzione d’acquisto: Il post indica l’intenzione di acquistare o di disdire?
- Influenza: Il post proviene da un account influente o da un consumatore medio?
- Virality: Il post ha potenziale di propagazione?
- Urgenza: Il segnale richiede una reazione rapida?
Analizza il sentiment con X Search e Grok
Analisi del sentiment per il tuo brand
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
Analisi comparativa del sentiment
Confronta la percezione del tuo brand con quella dei tuoi concorrenti:
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
Ottieni risultati strutturati in JSON
Per integrare l’analisi del sentiment in una pipeline di dati, richiedi un output JSON:
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
Monitora l’evoluzione del sentiment nel tempo
L’analisi una tantum è utile, ma il monitoraggio nel tempo rivela i trend. Confronta i risultati settimana dopo settimana:
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
Rileva le crisi di reputazione
L’analisi del sentiment è il tuo primo sistema di allerta in caso di crisi:
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"]}
Punti chiave
- L’analisi del sentiment va oltre il positivo/negativo: valuta intenzione, influenza e urgenza
- Usa una scala a 5 livelli per cogliere le sfumature
- Richiedi output JSON strutturati per alimentare le tue dashboard
- Monitora l’evoluzione del sentiment nel tempo, non solo istantanee una tantum
- Confronta sistematicamente il tuo sentiment con quello dei concorrenti
- Configura soglie di allerta per rilevare le crisi di reputazione non appena emergono