When setting up a tag-based conversion action, you can either set a fixed value or a dynamic value each time a conversion is fired. This article will walk you through how to track dynamic values in Conversion Tracking.
- Fixed Value: This will assign the same conversion value to all conversions each time the tag is fired.
- Dynamic Value: A dynamic value will assign a different value to each conversion depending on the value you pass to it when the tag is fired.
Dynamic values are useful when each conversion for your conversion action has a different value. For example, if you have an electronics store selling products, ranging from $5 HDMI cords to $5,000 TVs, you want to make sure you’re attributing the actual value of the purchase to each conversion as they can vary significantly. Using a dynamic value in these instances will give you a more accurate measure of the monetary value that your Yext products are driving.
To set up dynamic values for Tag-based Conversions:
- Create a Tag-based conversion action in Yext.
- To do this, follow the steps in Create a Conversion Action for Tag-based conversion action, and make sure to select Use different values for each conversion for the Conversion Value.
- Retrieve your Conversion Tag.
- Once you create your action, click Analytics in the navigation bar, and click Conversion Tracking.
- Click Conversion Setup.
- Select the name of the conversion action that you have created.
- Click Install the tag yourself and copy the conversion tag.
Modifying your Conversion Tag
Once you’ve created your Tag-Based Conversion Action and copied the code from the platform the next step is to modify it to track dynamic conversion values for your Conversion Action.
The way you will modify this code will vary depending on if you are installing conversion tags manually on your site, or using a Tag Manager.
While there are many ways to configure your Conversion Tag to track dynamic conversion values, this article will walk you through the following two methods:
JavaScript
If you are installing your tags without a Tag Manager, one way to set up a dynamic value is by creating a JavaScript function that retrieves the value for a conversion and then fires your conversion tag using that value.
Before installing the conversion tag and creating your JavaScript function, read below to understand each component of the standard conversion tag that is provided in the Yext platform.
Components of the Yext Conversion Tag
This is an example of a conversion tag that you copied from the platform:
<script>
window.ytagQ = window.ytagQ || [];
function ytag() {window.ytagQ.push(arguments);}
ytag('conversion', {'cid': bXX-1XX-4XX-aXX-5XX',cv: conversion_value'});
</script>
<script async src="https://assets.sitescdn.net/ytag/ytag.min.js"></script>
Initializing the ytag Function:
The first two lines window.ytagQ …
and functionytag() {window...
and the last line <script async src=https://assetts….ytag.min.js.”/></script>
initializes the ytag
function and points to executing an external Yext script file via the src
attribute https://assets.sitescdn.net/ytag/ytag.min.js
.
Note: These lines must remain in the header of the page.
Calling ytag Function:
The ytag('conversion',...)
function is what signals the completed conversion and passes parameters to the external Yext script file. The two parameters are:
- A conversion id
'cid'
ties the consumer’s conversion action to a specific, defined conversion action that is configured in Yext. The'cid'
is automatically set by Yext for each conversion action created and is what makes this tag unique. - A conversion value
'cv'
can be passed to denote an explicit value associated with the conversion. This parameter is optional and is leveraged only when the conversion action is using a unique value per conversion (as opposed to a conversion action that always uses or assumes the same value).
The ytag
function does not have to be in the header of the page. The instructions below outline how you can use this function in other places on your page depending on what you are trying to track.
Initializing the Analytics Library
Place the following bit of code, shown below, in then the header section of your site. This will allow the Conversion Tag library to be initialized so it can be used with your Conversion Tag.
<header>
<script>
window.ytagQ = window.ytagQ || [];
function ytag() {window.ytagQ.push(arguments);}
</script>
<script async src="https://assets.sitescdn.net/ytag/ytag.min.js"></script>
</header>
Firing your Conversion Tag
There are two primary ways that users will fire a Conversion Tag for their site:
- On Page Load: This will fire a Conversion Tag whenever the page loads. This is most common when the Conversion Tag is being placed on a page where no further action needs to be taken to confirm a Conversion was completed e.g. Order Confirmation page.
- On Click: This will fire a Conversion tag whenever a click you’ve specified is completed. This is most common when the Conversion Tag is being placed on a click that will lead you to a page you do not own e.g. Click from Search result to the App Store.
Firing the Conversion Tag on Page Load
The following code for the body fires the conversion on a Page Load using a dynamic value:
<body>
<script>
function findConversionValue() {
var conversion_value = document.getElementById("cost").value
ytag('conversion', {'cid': ‘{YOUR_CONVERSION_ACTION_ID’}’, 'cv': conversion_value });
}
</script>
findConversionValue()
</body>
findConversionValue()
as the purpose of this function is to find a conversion value from an element on the page and pass that to the conversion tag. Here you can see we’re creating a function in the <body> tag named findConversionValue()
that does the following:
- Retrieves a conversion value by using the
getElementById()
method to look up a field based on its ID named “cost” and stores that value in a variable namedconversion_value
.- The
getElementById()
is a DOM Method that returns the element that has the ID attribute with the specified value.
- The
- Inserts that variable named
conversion_value
into the conversion value parameter'cv'
in the ytag() function.
You can then call this function findConversionValue()
by placing it anywhere in your code beneath the <script> tag where we originally defined it to fire your Conversion tag on when the page loads.
Firing the Conversion Tag on Click
If you would like to fire the tag when a user clicks an Input Button, e.g. a Submit button when completing a form, you can call your newly created function findConversionValue()
using the onclick parameter as shown below.
<body>
<script>
function findConversionValue() {
var conversion_value = document.getElementById("cost").value
ytag('conversion', {'cid':' '{YOUR_CONVERSION_ACTION_ID'},cv: conversion_value});}
</script>
<input type="submit" value="Submit" id="submit" name="submit" onclick="findConversionValue()"/>
</body>
If you would like to fire the tag when a user clicks a Link, you can do this in a similar way by calling your findConversionValue()
function using the onclick parameter as shown below.
<body>
<script>
function findConversionValue() {
var conversion_value = document.getElementById("cost").value
ytag('conversion', {'cid':' ‘{YOUR_CONVERSION_ACTION_ID’},cv: conversion_value});}
</script>
<div class="Answers-alertBanner">my button <a href="yext.com" onclick=findConversionValue() });> here</a></div>
</body>
Google Tag Manager
If you decide to install your Conversion Tag using a Tag Manager like Google Tag Manager one way to set up a dynamic value is by using a dataLayer variable.
Creating a DataLayer
On your Website
To create a dataLayer object on your website add the following code to your site wherever you’re looking to fire a Conversion Tag.
<script>
dataLayer = [];
dataLayer.push({'variableName': document.getElementbyId("elementIdName").value});
</script>
dataLayer = []
represents an empty array you’re creating to store the variables you’d like to capture, in this case, your Conversion Value.dataLayer.push( )
will be used to push the variable (in this case we’re calling it'variableName'
) along with its value (in this case we’re looking it up based on the Element ID) to Google Tag Manager.
In Google Tag Manager
Once you’ve created the dataLayer object and added it to your website the next step is to go into Google Tag Manager to configure this dataLayer for your Conversion Tag.
- Click the Variables tab.
-
Click New in the User-Defined Variables tile.
- Click on the Variable Configuration tile and select Data Layer Variable.
- Enter the variable name you have defined in your data layer. In this example, we used 'variableName'.
- Navigate back to your Yext Conversion Tag and select your new Data Layer variable for the Conversion Value field.
Comments
0 comments
Please sign in to leave a comment.