developer

JavaScript SDK client side integration

The plenigo JavaScript-SDK offers the possibility to implement the plenigo functionality without a need for a server side request.

General functionality

The plenigo JavaScript-SDK offers additional functionality in addition to the PayWall functionality. These functions are completely independent from the usage of the SDK.

If you are using one of the plenigo SDKs you may not need all the functionality because the SDKs may already encapsulate some calls. Please refer to the according SDK documentation to cover this up.

Functions that are not covered on this page are used by your own risk. Only functions covered here will be supported by plenigo and are guaranteed to live up. If a function disappears it normally isn’t needed anymore and if you are still using it nothing happens. But you could also remove this function. Functions that must be replaced with other functions are marked as deprecated with an end date mentioned.

Start - Initialization call

The plenigo JavaScript-SDK initialize itself automatically when it is included in the HTML page after the page is loaded completely. If you are loading the Javascript-SDK manually after the page is loaded you need to start the initialization by calling this method.

/**
 * Initialize the plenigo JavaScript-SDK.
 */
plenigo.start();

Checkout - Start a plenigo checkout

This function offers the possibility to start a checkout process for the customer including the login and registration process of plenigo.

/**
 * Start a checkout process.
 * 
 * @param {object} configuration              
 */
plenigo.checkout(configuration);

The following tables describes the configuration object. Non mandatory parameters can be filled with null.

Name Type Mandatory Description
paymentData string Yes The encrypted and signed checkout string containing checkout information
startWithRegistration boolean Yes Flag indicating if the process should start with the login or the registration screen.
sourceUrl string No The source url for the checkout. This is only needed for better analytics.
targetUrl string No Url the checkout process should redirect after being finished. If empty it will redirect to the current page.
affiliateId string No Id of the affiliate defined in the plenigo backend. The affiliate module must be purchased for this functionality.
elementId string No If you want to start the checkout in embedded mode you have to pass the id of the element the checkout iFrame should be inserted to here.

Checkout with remote login - Start a plenigo checkout with external user management

This function offers the possibility to start a checkout process for the customer including the login and registration process of plenigo.

/**
 * Start checkout process for external managed users.
 * 
 * @param {object} configuration              
 */
plenigo.checkoutWithRemoteLogin(configuration);

The following tables describes the configuration object. Non mandatory parameters can be filled with null.

Name Type Mandatory Description
paymentData string Yes The encrypted and signed checkout string containing checkout information.
loginToken string Yes Login token to verify the user identity.
sourceUrl string No The source url for the checkout. This is only needed for better analytics.
targetUrl string No Url the checkout process should redirect after being finished. If empty it will redirect to the current page.
affiliateId string No Id of the affiliate defined in the plenigo backend. The affiliate module must be purchased for this functionality.
elementId string No If you want to start the checkout in embedded mode you have to pass the id of the element the checkout iFrame should be inserted to here.

Login - Open the plenigo login window

This function offers the possibility to open up the plenigo login window. It is possible for the user to switch to the registration window if needed.

/**
 * Open up login screen.
 * 
 * @param {object} configuration              
 */
plenigo.login(configuration);

The following tables describes the configuration object. Non mandatory parameters can be filled with null.

Name Type Mandatory Partner only Description
ssoRedirectURL string No No Redirect URL for the OAuth2 login process if OAuth2 is used.
scope string No No Scope of the OAuth2 login process. Currently the only available scope is profile
state string No No CSRF token for the OAuth2 process to use. This way you can verify the request source.
elementId string No No If you want to start the login in embedded mode you have to pass the id of the element the checkout iFrame should be inserted to here.
targetUrl string No No Url redirect customer to after a successful login process. Will only be used if ssoRedirectUrl is not set.
partnerLogin boolean No Yes Flag indicating if it is a partner login. Cannot be used in combination with OAuth2.
origin string No Yes Origin parameter after a successful login.
testMode boolean No Yes Flag indicating if access should be checked for live or test mode
productIds string No Yes If set plenigo checks if the customer has bought one of the products passed here. The product ids must be comma separated. A detailed explanation follows bellow.
notCustomerUrl string No Yes Url to redirect user to after login if user has not bought any product

If the “productIds” parameter is passed the targetUrl will only be called if the customer has successfully bought a product. Otherwise the user will stay on the current page. If the user has bought a product the target url will be called with the following additional parameters.

Name Description
Id Email address of the user
d Today’s date, UTC, in YYYY-MM-DD format
r Always the value “none”
c MD5 Hash of Id, d, r, and the secret of the company the checkout is for

Registration - Open the plenigo registration window

This function offers the possibility to open up the plenigo registration window. It is possible for the user to switch to the login window if needed.

/**
 * Open up registration screen.
 * 
 * @param {object} configuration              
 */
plenigo.registration(configuration);

The following tables describes the configuration object. Non mandatory parameters can be filled with null.

Name Type Mandatory Partner only Description
ssoRedirectURL string No No Redirect URL for the OAuth2 login process if OAuth2 is used.
scope string No No Scope of the OAuth2 login process. Currently the only available scope is profile
state string No No CSRF token for the OAuth2 process to use. This way you can verify the request source.
elementId string No No If you want to start the login in embedded mode you have to pass the id of the element the checkout iFrame should be inserted to here.
targetUrl string No No Url redirect customer to after a successful login process. Will only be used if ssoRedirectUrl is not set.
loginIdentifier boolean No No If set the registration mask supports a merge of a new email address with an existing customer without valid email address.
partnerLogin boolean No Yes Flag indicating if it is a partner login. Cannot be used in combination with OAuth2.
origin string No Yes Origin parameter after a successful login.
testMode boolean No Yes Flag indicating if access should be checked for live or test mode
productIds string No Yes If set plenigo checks if the customer has bought one of the products passed here. The product ids must be comma separated. A detailed explanation follows bellow.
notCustomerUrl string No Yes Url to redirect user to after login if user has not bought any product

If the “productIds” parameter is passed the targetUrl will only be called if the customer has successfully bought a product. Otherwise the user will stay on the current page. If the user has bought a product the target url will be called with the following additional parameters.

Name Description
Id Email address of the user
d Today’s date, UTC, in YYYY-MM-DD format
r Always the value “none”
c MD5 Hash of Id, d, r, and the secret of the company the checkout is for

Forgot Password - start a forgot password process

With this function you can display the forgot password window to let users change their password. It is recommended, if you imported users with an external subscription ID and without any password. In these cases your customers have to set a new password.

/**
 * Open up password forgotten screen.
 *
 * @param {object} params
 */

plenigo.passwordForgotten({object});

The following tables describes the configuration object. Non mandatory parameters can be filled with null.

Name Type Mandatory Partner only Description
ssoRedirectURL string No No Redirect URL for the OAuth2 login process if OAuth2 is used.
scope string No No Scope of the OAuth2 login process. Currently the only available scope is profile
state string No No CSRF token for the OAuth2 process to use. This way you can verify the request source.
elementId string No No If you want to start the login in embedded mode you have to pass the id of the element the checkout iFrame should be inserted to here.
targetUrl string No No Url redirect customer to after a successful login process. Will only be used if ssoRedirectUrl is not set.
partnerLogin boolean No Yes Flag indicating if it is a partner login. Cannot be used in combination with OAuth2.
origin string No Yes Origin parameter after a successful login.
testMode boolean No Yes Flag indicating if access should be checked for live or test mode
notCustomerUrl string No Yes Url to redirect user to after login if user has not bought any product

Logout - Logout the user

This function deletes the user’s login cookie. It doesn’t have any additional functionality.

/**
 * Logout the user.
 * 
 * @param {object} configuration              
 */
plenigo.logout({object});

Is user logged in - Indicates if the user is currently logged in

This function indicates if the user is logged in.

/**
 * Get flag indicating if user is logged in.
 *
 * @returns {*|boolean} true if the user is logged in false otherwise
 */
plenigo.isUserLoggedIn();

Reset layer opened detection - reset detection to prevent double opened login and checkout layers

Reset the detection for preventing double opened login and checkout layers.

/**
 * Resets the SDKs detection to prevent double opened login and checkout layers.
 */
plenigo.resetLayerOpenedDetection();

Usage examples

Following are a few examples of the usage for JavaScript-SDK.

JavaScript only checkout

The JavaScript only checkout can be used on LandingPages or something similar. This way you can integrate plenigo easily on pages where you don’t have direct control over the server side code execution.

To get a working example you have to replace some variables. Variables to are starting and ending with a dollar sign, e.g. $COMPANY_ID$ and described in a comment.

<!DOCTYPE html>
<html>
    <head>
        <title>Greatest product ever!</title>
    
        // Replace $COMPANY_ID$ with the company id from the plenigo merchant backend. 
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/$COMPANY_ID$/plenigo_sdk.min.js"
            data-disable-metered="true">
        </script>
        
        <script type="application/javascript">
            // Replace $CHECKOUT_STRING$ with the checkout string of the product that you can retrieve 
            // from the product overview page in the plenigo backend.
            // Replace $TARGET_URL$ with the url the checkout should redirect after being finished. Could be
            // a thank you page.
            var checkoutConfig = {
                paymentData: "$CHECKOUT_STRING$",
                startWithRegistration: "true",
                sourceUrl: null,
                targetUrl: "$TARGET_URL$",
                affiliateId: null,
                elementId: null
            }
        </script>
    </head>
    <body>
        <h2>The greatest product ever available</h2>
        
        
        <p>
            This is your chance to buy the best product ever available!
            
            <button onclick="plenigo.checkout(checkoutConfig); return false;">
                Buy now
            </button>
        </p>
    </body>
</html>

Snippets functionality

The plenigo JavaScript-SDK offers you the possibility to enable your users to do self management of their user data, orders, subscriptions, etc. This way you provide a whole backend functionality without great programming efforts. What kind of data the user can see and edit can be freely defined by you. Only show the snippets you want the user to see. Snippets are only available in embedded mode.

The snippet call expects the following parameters. All of these parameters are mandatory.

Parameter Type Description
elementId string The id of the HTML element the snippet should be rendered into.
snippetId string The snippet type that should be rendered. there are predefined constants listed below.
loggedOutRedirectUrl string It is strongly recommended that you check if a user is logged in before showing a snippet. If you don’t do this check the user will be redirected to this URL if the user is not logged in.
loginToken string string The login token is the optional fourth parameter. It is only necessary and mandatory if the plenigo user management is not used but an external user management.

Otherwise you can use one parameter as an object with the following keys

Parameter Type Description
elementId string The id of the HTML element the snippet should be rendered into. (mandatory)
snippetId string The snippet type that should be rendered. there are predefined constants listed below. (mandatory)
loggedOutRedirectUrl string It is strongly recommended that you check if a user is logged in before showing a snippet. If you don’t do this check the user will be redirected to this URL if the user is not logged in. (mandatory)
loginToken string The login token is the optional fourth parameter. It is only necessary and mandatory if the plenigo user management is not used but an external user management. (mandatory)
edit boolean Opens the snippet either in view or in edit mode. This works only for PERSONAL_DATA_ADDRESS snippet. (optional)

Snippets that combine different elements

  • plenigo.Snippet.PERSONAL_DATA
  • plenigo.Snippet.ORDER
  • plenigo.Snippet.SUBSCRIPTION
  • plenigo.Snippet.PAYMENT_METHODS
  • plenigo.Snippet.ADDRESS_DATA

Single elements

  • plenigo.Snippet.BILLING_ADDRESS_DATA
  • plenigo.Snippet.DELIVERY_ADDRESS_DATA
  • plenigo.Snippet.BANK_ACCOUNT
  • plenigo.Snippet.CREDIT_CARD
  • plenigo.Snippet.PERSONAL_DATA_SETTINGS
  • plenigo.Snippet.PERSONAL_DATA_ADDRESS
  • plenigo.Snippet.PERSONAL_DATA_PROTECTION
  • plenigo.Snippet.PERSONAL_DATA_SOCIAL_MEDIA
  • plenigo.Snippet.PERSONAL_DATA_PASSWORD

Example snippet for the JavaScript to render a personal data snippet.

<head><script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-disable-metered="true"></script></head>
<body>
    <div id="plenigoSnippet"></div>

    <!-- End of the HTML body. Not really necessary, but possible -->
    <script type="application/javascript">
        // we render the personal data snippet in this example ( parameter style)
        plenigo.renderSnippet("plenigoSnippet", plenigo.Snippet.PERSONAL_DATA, "https://www.YOUR_DOMAIN.com/");
    
    
        // we render the snippet in object style
        plenigo.renderSnippet({ 
            elementId:"plenigoSnippetPersonalData", 
            snippetId: plenigo.Snippet.PERSONAL_DATA_ADDRESS, 
            loggedOutRedirectUrl: "https://www.YOUR_DOMAIN.com/", 
            edit: false 
        });
    </script>
</body>

PayWall functionality

If you plan to use the PayWall functionality of plenigo you have to choose between three different use cases:

Hide content afterwards

The content will be visible on the page from the beginning and the plenigo JavaScript-SDK is going to hide it if the user is not allowed to see the content. If JavaScript is disabled or the user blocks the plenigo JavaScript-SDK she can access the whole page without any restrictions.

The plenigo JavaScript checks if the user has all rights necessary to see the content and if not the content is replaced with an up selling window or anything else. To integrate the JavaScript SDK add the following line to your template/html. The COMPANY_ID variable must be replaced with the actual company id.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true"></script>

There are additional configuration options. This options are added as attributes to the JavaScript tag.

Attribute Mandatory Values Description
data-disable-metered No true/false Deactivates the metered functionality and all the logic coming with it.
data-hide-metered-counter No true/false If set to true the plengio metered counter widget is not shown to the user.
data-lang No de/en Set the language used for metered counter, etc. If not set the browser language is taken.
data-client-paywall Yes true Must be set to enabled client side PayWall.
data-test-mode No true/false Flag indicating if test mode should be used.
data-paywall-type Yes hide Indicates the client side PayWall type.
data-paywall-source-element-id Yes id of the element to get the content from. id of the element to get the content from.
data-paywall-target-element-id Yes id of the element to add the content to. id of the element to add the content to.
data-paywall-registration-element-id Yes, if two two phase metered is planed id of the element containing the registration/login form. id of the element containing the registration/login form.
data-product-id Yes product id of the product on this page. Product id that identifies the product that is sold on this page.
data-login-status No function to call after user status change. Function that should be called if user status changed. The only argument passed is the status as boolean value.
data-oauth2-access-code No function to call after OAuth2 was successful. Function that should be called if OAuth2 is done. The only argument passed is the access code.
data-payment-check No function to call to check if the user has bought the product. This method is only called if the user is logged in successfully and the check should be done.  
data-original-site-url No original site url Original site url to detect if some kind of webproxy is used and prevent the user to access the site in this case.
data-metered-description-url No metered description url Link to a page that describes the metered model.
data-profile-security-label No true/false Do not show a security label around the profile snippets if rendered on a non https site.
data-disable-redirect No true/false Flag indicating if there should be a redirect after the user has logged in or bought something.

Example snippet for the JavaScript to include if you use the client side PayWall and hide the content if user has not bought the product.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true" data-paywall-type="hide" data-paywall-source-element-id="upselling-teaser" data-paywall-target-element-id="page-content" data-product-id="product"></script>

A complete example page where you only need to insert your data. This example assumes you are running in test mode with metered views enabled.

<!DOCTYPE html>
<html>
    <head>
        <title>A great news page </title>
    
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true" data-paywall-type="hide" data-paywall-source-element-id="sourceId" data-paywall-target-element-id="targetId" data-product-id="YOUR_PRODUCT_ID" data-test-mode="true">
        </script>
    </head>
    <body>
        <h2>This is the content area</h2>
        
        <div id="targetId">
            <p>
                This is the content you waited for!
            </p>
        </div>
        <div id="sourceId" style="display:none;">
            <p>
                You don't have the right to see this content! Sry!
                <button onclick="plenigo.checkout({paymentData: 'CHECKOUT_STRING'})">
                    Buy now
                </button>
                <button onclick="plenigo.login();">
                    Login
                </button>
            </p>
        </div>
    </body>
</html>

Hide content by default

The content will be placed in an HTML element that is hidden. After the user was verified to be allowed to see the content the content will be made visible by the plenigo JavaScript-SDK. The user is still able to access the content in the HTML sources.

The plenigo JavaScript checks if the user has all rights necessary to see the content and if the content is accessible the CSS style that hides the content is removed and the up selling window is hidden. To integrate the JavaScript SDK add the following line to your template/html. The COMPANY_ID variable must be replaced with the actual company id.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true"></script>

There are additional configuration options. This options are added as attributes to the JavaScript tag.

Attribute Mandatory Values Description
data-disable-metered No true/false Deactivates the metered functionality and all the logic coming with it.
data-hide-metered-counter No true/false If set to true the plengio metered counter widget is not shown to the user.
data-lang No de/en Set the language used for metered counter, etc. If not set the browser language is taken.
data-client-paywall Yes true Must be set to enabled client side PayWall.
data-test-mode No true/false Flag indicating if test mode should be used.
data-paywall-type Yes show Indicates the client side PayWall type.
data-paywall-source-element-id Yes id of the element to get the content from. id of the element to get the content from.
data-paywall-target-element-id Yes id of the element to add the content to. id of the element to add the content to.
data-paywall-registration-element-id Yes, if two two phase metered is planed id of the element containing the registration/login form. id of the element containing the registration/login form.
data-product-id Yes product id of the product on this page. Product id that identifies the product that is sold on this page.
data-login-status No function to call after user status change. Function that should be called if user status changed. The only argument passed is the status as boolean value.
data-oauth2-access-code No function to call after OAuth2 was successful. Function that should be called if OAuth2 is done. The only argument passed is the access code.
data-payment-check No function to call to check if the user has bought the product. This method is only called if the user is logged in successfully and the check should be done.  
data-original-site-url No original site url Original site url to detect if some kind of webproxy is used and prevent the user to access the site in this case.
data-metered-description-url No metered description url Link to a page that describes the metered model.
data-profile-security-label No true/false Do not show a security label around the profile snippets if rendered on a non https site.
data-data-disable-redirect No true/false Flag indicating if there should be a redirect after the user has logged in or bought something.

Example snippet for the JavaScript to include if you use the client side PayWall and show the content if user has bought the product.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true" data-paywall-type="show" data-paywall-source-element-id="page-content" data-paywall-target-element-id="upselling-teaser" data-product-id="productId"></script>

A complete example page where you only need to insert your data. This example assumes you are running in test mode with metered views enabled.

<!DOCTYPE html>
<html>
    <head>
        <title>A great news page </title>
    
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true" data-paywall-type="show" data-paywall-source-element-id="sourceId" data-paywall-target-element-id="targetId" data-product-id="YOUR_PRODUCT_ID" data-test-mode="true"> </script>
    </head>
    <body>
        <h2>This is the content area</h2>
        
        <div id="targetId">
            <p>
                You don't have the right to see this content! Sry!
                <button onclick="plenigo.checkout({paymentData: 'CHECKOUT_STRING'})">
                    Buy now
                </button>
                <button onclick="plenigo.login();">
                    Login
                </button>
            </p>
        </div>
        <div id="sourceId" style="display:none;">
            <p>
                This is the content you waited for!
            </p>
        </div>
    </body>
</html>

Load content afterwards

The content to be protected isn’t on the site at all. After the user was verified to be allowed to see the content the content will be loaded by another URL. If the user disables JavaScript or blocks the plenigo JavaScript-SDK he will not be able to see the content. It is also not visible in the HTML sources.

The page is only rendered with a teaser and an up selling window or anything else defined. The plenigo JavaScript checks if the user has all rights necessary to see the content and if the content is accessible it loads the complete article snippet from another URL not visible to the user. To integrate the JavaScript SDK add the following line to your template/html. The COMPANY_ID variable must be replaced with the actual company id.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true"></script>                      

There are additional configuration options. This options are added as attributes to the JavaScript tag.

Attribute Mandatory Values Description
data-disable-metered No true/false Deactivates the metered functionality and all the logic coming with it.
data-hide-metered-counter No true/false If set to true the plengio metered counter widget is not shown to the user.
data-lang No de/en Set the language used for metered counter, etc. If not set the browser language is taken.
data-client-paywall Yes true Must be set to enabled client side PayWall.
data-test-mode No true/false Flag indicating if test mode should be used.
data-paywall-type Yes url Indicates the client side PayWall type.
data-paywall-base-url Yes base URL to find real content Base URL to find real content for. To access the content the product id will be hashed with MD5 and added to the paywall-base-url.
data-paywall-target-element-id Yes id of the element to add the content to. id of the element to add the content to.
data-paywall-external-content-id Yes id of the external content The MD5 hash of this value will identify the external content.
data-paywall-registration-element-id Yes, if two two phase metered is planed id of the element containing the registration/login form. id of the element containing the registration/login form.
data-product-id Yes product id of the product on this page. Product id that identifies the product that is sold on this page.
data-login-status No function to call after user status change. Function that should be called if user status changed. The only argument passed is the status as boolean value.
data-oauth2-access-code No function to call after OAuth2 was successful. Function that should be called if OAuth2 is done. The only argument passed is the access code.
data-payment-check No function to call to check if the user has bought the product. This method is only called if the user is logged in successfully and the check should be done.  
data-original-site-url No original site url Original site url to detect if some kind of webproxy is used and prevent the user to access the site in this case.
data-metered-description-url No metered description url Link to a page that describes the metered model.
data-profile-security-label No true/false Do not show a security label around the profile snippets if rendered on a non https site.
data-disable-redirect No true/false Flag indicating if there should be a redirect after the user has logged in or bought something.

Example snippet for the JavaScript to include if you use the client side PayWall and load the content from another url if user has not bought the product.

<script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js" data-client-paywall="true" data-paywall-type="url" data-paywall-base-url="http://example.com" data-paywall-target-element-id="targetId" data-product-id="productId" data-paywall-external-content-id="externalContentId"></script>

A complete example page where you only need to insert your data. This example assumes you are running in test mode with metered views enabled.

<!DOCTYPE html>
<html>
    <head>
        <title>A great news page </title>
    
        <!--
        The following configuration will load the content from the following url after
        the user has bought YOUR_DOMAIN_URL/MD5(YOUR_IDENTIFIER_FOR_THIS_CONTENT).
        Let's use concrete values
        data-paywall-base-url="http://example.com" (has to be the same domain like the page)
        data-paywall-external-content-id="great-article-number-one"
        would produce the following url
        http://example.com/a0048edd23a9aa85e37c248bd28f270b
        -->
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/COMPANY_ID/plenigo_sdk.min.js"
                data-client-paywall="true" data-paywall-type="url" data-paywall-base-url="YOUR_DOMAIN_URL"
                data-paywall-target-element-id="targetId" data-product-id="YOUR_PRODUCT_ID" data-paywall-external-content-id="YOUR_IDENTIFIER_FOR_THIS_CONTENT">
        </script>
    </head>
    <body>
        <h2>This is the content area</h2>
        
        <div id="targetId">
            <p>
                You don't have the right to see this content! Sry!
                <button onclick="plenigo.checkout({paymentData: 'CHECKOUT_STRING'})">
                    Buy now
                </button>
                <button onclick="plenigo.login();">
                    Login
                </button>
            </p>
        </div>
    </body>
</html>

Web Statistics

As by design, the SDK opens up an iframe to offer the plenigo checkout process. This makes it difficult to track the user experience through this process. With the plenigo module web analytics we offer you a look inside this process and give the missing data.

Installation

The installation is just adding the new attribute data-on-action to your plenigo SDK call:

<!DOCTYPE html>
<html>
    <head>
        <title>Track even interactive elements</title>
    
        // Replace $COMPANY_ID$ with the company id from the plenigo merchant backend. 
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/$COMPANY_ID$/plenigo_sdk.min.js"
            data-disable-metered="true"
            data-on-action="statisticFunction">
        </script>
  ```
 
You are free to name the method _statisticFunction_. It can be a method at an object, but has to be accessible or be part of the _window_ object. 

### Debugging

To debug this function simply use the _console_ function:

```html
<script>
  var statisticFunction = function (data) { console.log(data) }
</script>

On Submit this will result in the following data:

// on submit
data = {
    action: "submit"
    data: [
      0: {name: "userCountry", value: "DE"}
      1: {name: "userState", value: ""}
      2: {name: "billingAddressNeeded", value: "false"}
      3: {name: "paymentMethod", value: "BILLING"}
      4: {name: "useVoucher", value: "true"}
      5: {name: "ageVerification", value: "false"}
      ]
};

// on load
data = { 
    action:"load"
    data: [],
    page: "previousStep",
    pageName: "basket",
    product: "" // will be set on the basket page
    };
    

working with Events

If your tracking javascript code should not be accassible from outside, you should use our tracking events:

document.addEventListener("plenigo.Statistic", function(e) {
    // debugging Code:
    console.info("Event is: ", e);
    console.info("Custom data is: ", e.detail);
});

The additional data-on-action attribute is not used.

Description of data

The onAction Callback gets some data to have a better look inside of tho plenigo checkout process. Best way to know the path, your customer takes through the checkout is, tracking each page of the checkout process. This is done by only taking calls with action === "load". In these cases you will miss some data and get the name of the page on pageName. Since one can easily change the product during the checkout, we will put in the productID on the product-parameter whenever the change of it is done. This should always be the basket page.

// valid pageNames are:
basket
payPalSummary
payPalRedirect
zeroPayment
creditCardSummary
invoiceAddress
selectCreditCard
invoiceAddressVerification
enterCreditCard
voucher
bankAccountSummary
enterBankAccount
sofortUeberweisungSummary
selectBankAccount
sofortUeberweisungRedirect
paymentFailed

Example with analytics

To get a working example you have to replace some variables. Variables to are starting and ending with a dollar sign, e.g. $COMPANY_ID$ and described in a comment.

<!DOCTYPE html>
<html>
    <head>
        <title>Greatest product ever!</title>
    
        // Replace $COMPANY_ID$ with the company id from the plenigo merchant backend. 
        <script type="application/javascript" src="https://static.plenigo.com/static_resources/javascript/$COMPANY_ID$/plenigo_sdk.min.js"
            data-disable-metered="true"
            data-on-action="statistics.checkout">
        </script>
        
        <script type="application/javascript">
            var statistics = {
                checkout: function(data) {
                    var i = 0, form = [];
                    // checks, if analytics is fully initialized
                    if (typeof ga === "undefined") {
                        return;
                    }

                    if (data.action === "load") {
                        ga("send", {
                            hitType: "pageview",
                            page: "/checkout/" + data.pageName
                        });
                    } else if (data.action === "submit") {
                        form = data.data || form;
                        for (i = 0; i < form.length; i++) {
                            if (form[i].name === "paymentMethod") {
                                ga("send", {
                                    hitType: "event",
                                    eventCategory: "PaymentMethod",
                                    eventAction: form[i].name,
                                    eventLabel: "plenigo"
                                });
                            }
                        }
                    }
                }
            };
        </script>
    </head>
    <body>
        <h2>The greatest product ever available</h2>
        
        
        <p>
            This is your chance to buy the best product ever available!
            
            <button onclick="plenigo.checkout(checkoutConfig); return false;">
                Buy now
            </button>
        </p>
    </body>
</html>

execute and read metered (SPA)

With normal configuration and metered enabled, the meter will count automatically on each page load. For Single Page Applications this will not work.

control metered

Even in Single Page Applications one have to control the metered behavior. This is done with a call of the method plenigo.countMeteredView. It needs one parameter to identify the actual view:

// define the config object
var config = {
  identifier: 'myActualView' // key to define the provided view
};

// execute the metered counter with given configuration
plenigo.countMeteredView(config);

get metered information

Not only in Single Page Applications one wants to read the actual metered status. You can use it in your statistic tools too. To read the metered status simply call plenigo.getMeteredViewInfo.


var info = plenigo.getMeteredViewInfo();

console.log(info);

// will output
info = {
  activated: true,
  browserId: "b17ef4299ec632302ab155f3b1bb9a42"
  cookieCreation: 1526971537227,
  cookieVersion: 1526980598208,
  fingerprint: "b17ef4299ec632302ab155f3b1bb9a42",
  freeAfterLogin: 10,
  freeAfterLoginTaken: 0,
  freeViews: 20,
  ignoreSearchEngines: true,
  ignoreSocialMedia: true,
  limitReached: false,
  limitReachedAfterLogin: false,
  onlyUniqueViews: true,
  period: "MONTH",
  startTime: 1525132800000,
  startWithFirstVisit: false,
  uniquelyVisitedSites: "05ee2a41,c4ca4238,c81e728d,eccbc87e,a87ff679,e1671797,a2e84d15",
  viewsTaken: 7
 };

Video-Player with access control

Based on the 3q video player plenigo offers you a video player with access control. You may need a 3q account one can create at 3q video

There one can upload multiple videos.

Installation

The installation is based on the 3qvideo player. All the configuration parameters you can see in their documentation

        window.plenigoVideoPlayer = window.plenigoVideoPlayer || [];

            plenigoVideoPlayer.push({
                'data-id': '5280e612-c311-11e8-ae4b-0cc47a188158', // Video ID from 3q backend
                'container': 'video1', // ID of HTML-Element in you html page
                'productIDs': 'P_PWywB6996251827351,P_ygHn66932077286351', // lst of plenigo product IDs to check access against
                'teaserLength': 2, // length of free videoteaser until video is stopped
                'no-access-callback': function (par1, par2) { // callbackfunction we call, if customer has no access
                    location.href = "/landingpage";
                }
            });
          

Example with full html

Just put the plenigo Jacascript call somewhere in your html. To enable video player, add attribute data-video="3q".


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
</head>
<body>

    <header class="main">
        <h1>My 1st video</h1>
    </header>


        <div id="video"></div>
    
    
<script type="application/javascript"
        src="https://static.plenigo.com/static_resources/javascript/$COMPANY_ID$/plenigo_sdk.min.js" 
        data-lang="de" 
        data-video="3q"></script>

<script>

        window.plenigoVideoPlayer = window.plenigoVideoPlayer || [];

            plenigoVideoPlayer.push({
                'data-id': '5280e612-c311-11e8-ae4b-0cc47a188158',
                'container': 'video',
                'productIDs': 'P_WWWWQQQQ27351,P_WWWWQQQQ77286351',
                'sticky': true,
                'playlistbar' : true,
                'teaserLength': 2,
                'no-access-callback': function (productIds, videoId) {

                    location.href = "/video/checkout";
                }
            });
    </script>

</body>
</html>

If the customer has not bought at least one of the products given in the productIDs parameter, it will call call function given in no-access-callback. Here one can simply call a landing page, or open a dialog or simply start a plenigo checkout.