We’ve migrated our documentation to a new site, which means some URLs have changed.
Subscriptions

How to assign a registration term to logged-in users

If you would like to programmatically assign a registration term to a user that is logged in, you can utilize the following code.

Please note, that you need to specify the term ID in the parameter registrationTermId.

tp = window["tp"] || [];
// Set your registration term
var registrationTermId = 'XYZ';
tp.push(["init", function(){
    // Check if user is logged in
    if (tp.user.isUserValid()){
        // Query API to get the list of conversions
        tp.api.callApi("/conversion/list", {}, function(listData){
            if (listData.code != 0){
                return;
            }
            var conversions = listData.conversions;
            // Go through user's conversions
            for (var i in conversions){
                // Is current conversion happened on our registration term?
                if (conversions[i].term.term_id == registrationTermId){
                    return;
                }
            }
            // Create a conversion on registration term automatically
            tp.api.callApi("/conversion/registration/create", {term_id: registrationTermId}, function( conversionData ){
                // Refresh access token cookie manually
                tp.user.refreshAccessToken(true, function( accessTokenList ){
                    // All done, here you can close the offer or refresh the page
                    tp.offer.close();
                    window.location.reload();
                });
            });
        });
    }
}]);

The front-end script required for assigning a registration term above can be placed on one or all pages where you are already loading the Piano script. This can be done directly in the front-end code of your website or by using a Run JS card via Composer Experience.

It's important to clarify that the script does not need to be placed on your back end. Similarly, the script should not be inserted within a template.

Frequently Asked Questions (FAQ)

Q: Is the registration term assigned each time users log in?

A: The registration term will not be applied if the user is already assigned to that registration term. Therefore, it won't be applied every time users log in.

Q: Does assigning a registration term in this way trigger any email?

A: Assigning a registration term in this way does trigger the "Completed registration" email. Users who gained access to a resource via the assigned registration term will receive the related term-specific emails (if enabled).

Q: If a user that should be assigned the registration term already has access to the same resource via a paid subscription term, will this access still be granted?

A: No, if the user already has access to the resource through a paid subscription term, the access will not be granted via the registration term assignment method.

Q: Why are manually logged conversions not included in the Management + Billing conversion report?

A: Manually logged conversions can appear in the Management + Billing conversion report, but only if they’re properly attributed to exposures. For the /conversion/registration/create endpoint, the pageview_id parameter should be included to enable accurate URL tracking; without it, conversions may show up with an "Unknown" page. For the /publisher/conversion/registration/create endpoint, logging exposures via the tbc parameter is recommended to ensure correct attribution. Exposures can also be logged separately via API using the /exposure/log API endpoint.

Last updated: