1
votes

I am having trouble identifying visitors who contact us through our website's contact form. The form collects basic information, but it would be nice to include some Sitecore Analytics data in the body of the email to help paint a bigger picture.

To achieve this, I would need to somehow retrieve all Campaigns and Goals triggered during the current session.

The Sitecore API provides convenient methods for "triggering" goals and campaigns, but I cannot seem to find any methods to retrieve what's been triggered for the current session. I would like to avoid querying the OMS database directly, if possible.

Any help is much appreciated.

2

2 Answers

0
votes

You can have a dig around in the VisitorDataSet object returned from Tracker.CurrentVisit, you should be able to get at some useful properties and then extract relevant data.

This, for example, should get you the campaign returned by the current visit (if there is a relevant campaign)..

if(!Tracker.CurrentVisit.IsCampaignIdNull())
{
    var campaignDataTable = new SharedDataSet.CampaignsDataTable();
    var data = campaignDataTable.FindByCampaignId(Tracker.CurrentVisit.CampaignId); 

    Response.Write("Campaign Name:" + data.CampaignName);
    Response.Write("Id:" + Tracker.CurrentVisit.CampaignId);    
}
else
{
    Response.Write("No campaign found!");
} 

I've not used this a lot but might get you going in the right direction, sorry I cant provide any more detail.

0
votes

I could not get the proposed answer to work, but I found a solution that does! It should be relevant for Sitecore 6.5 to 7.2 (not sure about 7.5 and beyond). You can access the campaigns through the Sitecore.Analytics.Tracker.DataContext object.

Combining this knowledge with the Stephen Pope's answer, we get:

using System.Linq;
using Sitecore.Analytics;

// won't be null if a campaign was triggered
if (!Tracker.CurrentVisit.IsCampaignIdNull())
{
    var campaign = Tracker.DataContext.Where(x => x.ID.Guid == Tracker.CurrentVisit.CampaignId).FirstOrDefault();

    if (campaign != null)
    {
        // do stuff with the campaign here
        var name = campaign.Title;
    }
}

I also cared about getting the campaign's traffic type, which you can do like so:

var trafficType = campaign.SelectTrafficType.TargetItem.Name;