DataLayer for Google Tag Manager
How To Configure
DataLayer for Google Tag Manager

Integrate CJ Affiliate with Google Tag Manager

Please Note: The settings below require our Datalayer for Google Tag Manager for Magento and some features also require our Enhanced Ecommerce extension.

All Page View

Set cookie if user is coming from a CJ Affiliate (site.com/?cjevent=abc123)

Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Pages

HTML

<script>
require(['DataLayerApi'], function (dataLayerApi) {
    var dataHelper = dataLayerApi();
    
    <!-- CJ Affiliate Code -->
    dataHelper.saveTrackingCodeIfKeyExist("cjevent");
    <!-- CJ Affiliate Code -->
});
</script>
Purchase
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : purchase

HTML

<script>
require(['DataLayerPurchaseApi'], function (dataLayerPurchaseApi) {
    var purchase = dataLayerPurchaseApi();

    var queryParms = {
        containerTagId: 'Add your Container Tag Id here',
        OID: purchase.getOrderId(),
        TYPE: 'Add your Type Id here',
        CURRENCY: purchase.getCurrencyCode(),
        DISCOUNT: purchase.getOrder('discount'),
        COUPON: purchase.getOrderCouponCode(),
        CJEVENT: purchase.getTrackingCodeIfKeyExist('cjevent', true)
    };
    
    var cjFormat = {
        renameFieldTo: {id:'ITEM', quantity:'QTY', price:'AMT'},
        appendIndex: true
    }; 
    
    var cjItems = purchase.getItems(cjFormat);
    
    purchase.setUrlDomain('//www.emjcd.com/tags/c/');
    purchase.addUrlParams(queryParms);
    purchase.addUrlParams(cjItems);
    
    var url = purchase.buildUrl();
    purchase.addIframe(url);
});
</script>
Related

Related Extensions

Get more from your Magento2 store!

Order Shipment Tracking

Providing your customer with a beautiful and functional order package tracking without leaving your site.

HTML Minifier for Magento2

Minification is the process of removing all unnecessary characters and spacing from your source code without changing its functionality.

Enhanced Transactional Emails

Get more from your order confirmation emails by promoting other complementary products.