Reputation: 2017
I am working on a solution where I need to read engagement values based on traffic types.
I tried with database query and it's working for me please see below code.
double totalValue = 0;
using (SqlConnection newCon = new SqlConnection(ConfigurationManager.ConnectionStrings["Analytics"].ConnectionString))
{
SqlCommand newCmd = new SqlCommand("SELECT SUM(Value) FROM Cache_TrafficByDay as totalValue WHERE (TrafficType = 20)", newCon);
newCon.Open();
SqlDataReader dr = newCmd.ExecuteReader();
while (dr.Read())
{
totalValue = Convert.ToDouble(dr[0]);
}
newCon.Close();
lblValue.Text = totalValue.ToString();
newCmd.ToString();
}
But I didn't find any API to do this where I can pass traffic type value and based on this traffic type value I can read engagement values.
Is there any direct method to read engagement values by passing traffic types?
Any help?
-Thanks, Yogesh
Upvotes: 0
Views: 194
Reputation: 2953
The most recent Engagement Analytics API Reference (for 6.5 or later) doesn't list any obvious choices for accessing engagement value by traffic type.
It does however provide Sitecore.Analytics.Data.DataAccess.DataAdapters.SqlBase
This is an abstract class which contains methods to build custom queries.
Edit to provide code example:
string query ="SELECT SUM {0}Cache_TrafficByDay{1}.{0}Value{1} from {0}Cache_TrafficByDay{1} WHERE {0}Cache_TrafficByDay{1}.{0}TrafficType{1} = 20"
Double totalValue = DataAdapterManager.Sql.ReadOne<Double>(query, reader =>DataAdapterManager.Sql.GetDouble(0, reader),new object[0]);
I've not tested this, I've merely edited one of the example queries provided in the doumentation (see link above), and I'm not sure which method of ReadOne or ReadMany you need to do a SUM. You might also need to return a string using .GetString and cast it to a double yourself.
Upvotes: 1