Track and report on UTM details of leads

Track campaign information from your online campaigns and report on its UTM tracking specifics of leads.

Keeping track of campaign information in CRM and reporting on their UTM tracking details can significantly benefit your business. It lets you pinpoint the most efficient campaigns in driving traffic and generating leads. In addition, tracking UTM details can help you better understand your visitors' behavior and identify any potential issues with your website or landing pages.

Presently, it's not possible to track UTM details inside a lead record in your CRM. However, you can write a custom function to track campaign information from your online campaigns and provide reports on its UTM tracking specifics. Read the section below to learn more.

Permissions and availability

  • Users with the Modules Customization permission can add custom fields.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Prerequisite

  • To capture and pass on the referrer URL for your UTM tracking, you must add a hidden field to your campaign forms and map it with the Referrer URL field in the leads module.

Requirements

  • Add a URL field and five single-line fields in the Leads module. The URL field will capture the referrer URL from your campaign form, while you can use the single-line fields to record campaign information. Learn more
  • Create a workflow rule for the Leads module that triggers every time the URL field contains "utm". Learn more
  • Write a custom Deluge function and link it up with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Add custom fields

The first step is adding the custom URL and single-line fields to the Leads module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Leads module to open the layout editor.
  3. Drag and drop the URL field from the New Fields tray to the desired section of the layout.
  4. Name the URL field (e.g. "Referrer URL") and define its properties as required.
  5. Drag and drop New Section from the New Fields tray to the desired location on the layout.
  6. Name the section (e.g. "UTM - Campaign Information") and define its properties as required.
  7. Similarly, drag and drop five Single Line fields from the New Fields tray to the above section. Name these fields as Campaign Name, Campaign Source, Campaign Medium, Campaign Term, and Campaign Content.
  8. Once you have finished, click Save and Close.
Add Custom Fields

Create a workflow rule

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Leads from the module dropdown list.
  3. Provide a name for the rule. For example: "Track UTM parameters for lead". 
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, choose Record Action, then select Create or Edit from the dropdown and click Next.
  6. In the Which leads would you like to apply the rule to? section, specify the condition as "<Referrer URL> contains <utm>" and click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name and description, if necessary, for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Leads - Lead Id and name it as leadId, then click Save.
    4. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
getLeads = zoho.crm.getRecordById("Leads",leadId);
referrerUrl = getLeads.get("Referrer_URL");
info referrerUrl;
urlVal = referrerUrl.indexOf("?");
customVariables = referrerUrl.substring(urlVal + 1);
utm_source = "";
utm_medium = "";
utm_campaign = "";
utm_term = "";
utm_content = "";
formMap = Map();
for each  customVariablesArr in customVariables.toList("&")
{
	var_s = getPrefix(customVariablesArr,"=");
	val_s = getSuffix(customVariablesArr,"=");
	if(var_s == "utm_source")
	{
		utm_source = val_s;
	}
	if(var_s == "utm_medium")
	{
		utm_medium = val_s;
	}
	if(var_s == "utm_campaign")
	{
		utm_campaign = val_s;
	}
	if(var_s == "utm_term")
	{
		utm_term = val_s;
	}
	if(var_s == "utm_content")
	{
		utm_content = val_s;
	}
}
formMap.put("Campaign_Sources",utm_source);
formMap.put("Campaign_Medium",utm_medium);
formMap.put("Campaign_Name",utm_campaign);
formMap.put("Campaign_Term",utm_term);
formMap.put("Campaign_Content",utm_content);
leadupdated = zoho.crm.updateRecord("Leads",leadId.toString(),formMap);
info leadupdated;

Notes

  • Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more

Idea

  • If you currently use Zoho Forms to capture leads, note that UTM tracking is already supported. Learn more
  • You can track the UTM parameters of your contact records by making minor adjustments to the code snippet.

Test the solution

  1. Fill out the campaign form to create a new lead containing a referrer URL in your CRM.
    The workflow rule will be triggered.
  2. Go to the Leads module and click on the newly created lead.
  3. On the Lead Details page, navigate to the UTM - Campaign Information section.
  4. Check whether the lead's UTM specifications, such as campaign name, campaign source, campaign medium, campaign term, and campaign content, are updated as per the campaign source.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleLeads
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityHigh
  • Implementation Time60 minutes

Features used in the solution

Custom FieldWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!