A Beginner’s Guide to Sitecore DMS – Part 2

In last post, we had seen how to set and trigger goal in DMS. If you remember – we have assigned BrochureDownload goal to ProductMannual PDF which got triggered whenever you click on PDF link. So we have seen one way of triggering goal, fine? Actually there are three ways of triggering goal in Sitecore DMS. In this post, we are going to uncover remaining two ways to trigger goal.

Which are three ways to trigger goal in sitecore DMS?

  1. Tirgger goal on user action (covered in last post)
  2. Trigger goal using query string (will be covered in this post)
  3. Trigger goal programmatically (will be covered in this post)

Now let’s see how to trigger goal using query string?

Sometimes you need to trigger goal without requiring user action. In such case you can take advantage of Sitecore query string variable sc_trk like this: http://plainsitecore7/?sc_trk=[goal name]

For Example: http://plainsitecore7/?sc_trk=BrochureDownload

The next thing in your mind may come – how can I check whether this query-string triggered your goal or not? You can check it at below section: How to check whether goal is triggered or not?

 

 Third way – how to trigger goal programmatically?

Before we proceed to see implementation of programmatically triggering goal, let’s see in which scenario you would need this?

Suppose you want to trigger a goal on button click, and you cannot assign goal to button from Sitecore content editor. In such case, you can go with third option – trigger goal programmatically.

Scenario:

Your site has feature to subscribe for product newsletter, and you need to trigger goal whenever any user subscribed for this newsletter.

Implementation:

Sitecore.Analytics API provides built-in methods to trigger your goal. Here is code that you can hook into button_click event.

protected void btnSubscribe_Click(object sender, EventArgs e)         {             if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.CurrentPage != null)             {                 Sitecore.Data.Items.Item GoaltoTrigger = Sitecore.Context.Database.GetItem("{1779CC42-EF7A-4C58-BF19-FA85D30755C9}");                 if (GoaltoTrigger != null)                 {                     Sitecore.Analytics.Data.Items.PageEventItem registerthegoal = new Sitecore.Analytics.Data.Items.PageEventItem(GoaltoTrigger);                     Sitecore.Analytics.Data.DataAccess.DataSets.VisitorDataSet.PageEventsRow eventData = Sitecore.Analytics.Tracker.CurrentPage.Register(registerthegoal);                     eventData.Data = GoaltoTrigger["Newsletter subscription"];                     Sitecore.Analytics.Tracker.Submit();                 }             }                    }

In above code snippet, Item ID-{1779CC42-EF7A-4C58-BF19-FA85D30755C9} is ID of your goal that you want to trigger on button click.

That’s it! Click on “Subscribe” button and it will trigger your “Newletter Signup” goal. The next question in your mind may come – how can I check whether goal is triggered or not?

How to check whether goal is triggered or not?

If you have this question in your mind, then at this time I hope you know answer of it also. Recall first post please, we have seen how to check report of “Goal and Events”. If not able to recall, no problem – let’s see report of this new goal – “Newsletter Signup” Select the page on which you have added “Newletter Subscribe” button -> go to “Analyze” menu -> click on “Reports” -> select “Page – Goals and Events” report. You will see report having “Newsletter Signup” goal there.

Friends, hope that you are now clear with all three ways to create “Goals” in DMS. Hope that this post series may help you in your DMS journey, will come with few more DMS points soon. Want to decide marketing strategy of your site? Use Sitecore DMS!

Leave a Reply