Edit your Smartserve prescript

This is for:

Developer

In this article, we’ll show you how you can use your prescript to run some JavaScript before any data collection or experience activation begins. For clients setting up Coveo Merchandising Hub (CMH) on the web, this script must be placed as early as possible on each of your site’s pages.

What is the prescript

The Smartserve prescript can be used to run JavaScript code before any data collection or campaign activation begins.

It allows you to implement a wide range of bespoke use cases, tailored to your specific requirements. Examples include:

  • Tracking campaign shown events in your third party analytics solution

  • Preventing Smartserve from firing based on specific conditions (e.g. a cookie value or URL parameter)

  • Setting up a QProtocol data layer mapper

Tip
Leading-practice

You can also manage your script through the Coveo Qubit CLI.

Open the prescript

Select Settings from the side menu and then Edit in the Prescript card.

Edit the prescript

Make sure that you’ve selected prescript.js from the side menu:

prescript

Make the required changes and select Save You can now return to the previous page by selecting X in the upper-right hand corner

Tip
Leading-practice

For examples of how the prescript can be used, see Code examples.

Note

To publish your changes, you’ll need to review and apply them.

Review and publish your changes

When you or a member of your team has made changes to the prescript, those changes need to be reviewed and applied before they can be published. We’ll notify you when there are changes ready for review.

In the following example, we see that there are unpublished changes and that the changes were made on October 17:

review-changes

To review those changes, select Review and apply changes.

So you can see what has been changed, we display a diff. In the following example, we see that a change was made on line 10:

changes-made

Enter a reason for the change. Be as descriptive as possible to help other team members understand why the change was made.

Select Publish

View a changelog

So you and your team can keep track of changes to the prescript, we provide a revision history that you can browse through.

To view the changelog, select Revision history. In the following example we see that there have been 4 revisions:

revision-history

You can now select a revision to see the changes in a diff and the reason. Select Previous revision and Next revision to cycle through the changes. To return to the revision history, select Revision history