Skip to main content
All CollectionsPredictive Personalization SuiteProduct Recommendations
On-site Recommendations: Coding Tips and Troubleshooting
On-site Recommendations: Coding Tips and Troubleshooting

Learn more about different troubleshooting and coding tips for On-site Recommendations.

Updated over 2 years ago

When coding your website recommendations, by adding parentheses after the @ symbol and around the variable, you can use any standard JavaScript to modify the data coming back for the variable. 

For example, if you want to say something other than null if you don’t have a description, you could modify your description with the following syntax:

<div data-ltk-merchandiseblock="[[YOUR MERCHANDISE BLOCK ID HERE]]">
    <script type="text/html">
        <a href="@(linkRoot + Recommendation.LinkUrl)">
            <img src="@(imageRoot + Recommendation.ImageUrl)" title="@(Recommendation.Description || 'No Description Available')" width="100px" style="display:block" />

            <strong>@Recommendation.Title</strong>
        </a>
    </script>
</div>

Or if you wanted to make your entire description lowercase, you could modify your description with the following syntax:

<div data-ltk-merchandiseblock="[[YOUR MERCHANDISE BLOCK ID HERE]]">
    <script type="text/html">
        <a href="@(linkRoot + Recommendation.LinkUrl)">
            <img src="@(imageRoot + Recommendation.ImageUrl)" title="@((Recommendation.Description || 'No Description Available').toLowerCase())" width="100px" style="display:block" />

            <strong>@Recommendation.Title</strong>
        </a>
    </script>
</div>

ADDING GOOGLE ANALYTICS EVENT TRACKING

To add google analytics to your recommendations, you can add this by adding an onclick event to your  tag in your code. Depending on which version of Google Analytics you are using, will determine which Google Analytics tracking you will add to your website.

In the below examples, you can see the full onclick event tag with the google analytics variables already filled out for you.

UNIVERSAL GOOGLE ANALYTICS (analytics.js)

<div data-ltk-merchandiseblock="[[YOUR MERCHANDISE BLOCK ID HERE]]">
    <script type="text/html">
        <a onClick="ga('send', 'event','Recommended Products', 'click', '@Recommendation.Title');" href="@(linkRoot + Recommendation.LinkUrl)">
            <img src="@(imageRoot + Recommendation.ImageUrl)" title="@Recommendation.Description" width="100px" style="display:block" />

            <strong>@Recommendation.Title</strong>
        </a>
    </script>
</div>

LEGACY GOOGLE ANALYTICS (ga.js)

<div data-ltk-merchandiseblock="[[YOUR MERCHANDISE BLOCK ID HERE]]">
    <script type="text/html">
        <a onClick="_gaq.push(['_trackEvent', 'Product', 'Recommended Products', '@Recommendation.Title',, false]);" href="@(linkRoot + Recommendation.LinkUrl)">
            <img src="@(imageRoot + Recommendation.ImageUrl)" title="@Recommendation.Description" width="100px" style="display:block" />

            <strong>@Recommendation.Title</strong>
        </a>
    </script>
</div>


Did this answer your question?