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!

Enhanced Success Page

Add cross-sell, upsell, related products, social media links and other elements to your order confirmation.

Magento Enhanced E-commerce

If your are using Magento + Google Analytics, then you need Enhanced E-commerce for Google Tag Manager.

Enhanced Transactional Emails

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