Skip to content

Instantly share code, notes, and snippets.

View webhasan's full-sized avatar
🎯
GTM, GA4, Conversion Tracking (Coding Ninja)

Md Hasanuzzaman webhasan

🎯
GTM, GA4, Conversion Tracking (Coding Ninja)
View GitHub Profile
@webhasan
webhasan / gist:8cff6d8f12640b65631115b7b8eee846
Last active April 7, 2024 08:53
Checkout DataLayer Modify
<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != "dataLayer" ? "&l=" + l : "";
j.async = true;
j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
@webhasan
webhasan / user-pixel.js
Created April 6, 2024 03:39
Shopify Pixel Events (Assignment)
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-K9W894CT');
/**
* View Cart
*/
@webhasan
webhasan / Shopifychat.html
Created March 30, 2024 06:37
Shopify Chat
<script>
(function() {
var trackedChatClick = false;
var customerFormSubmit = false;
var foundCustomerForm = false;
var foundChatButton = false;
var startChat = false;
@webhasan
webhasan / affiliate.js
Last active November 8, 2023 08:16
Affiliate Link Tracking with GTM Code
// example affiliate link
// https://leocoder-shop.myshopify.com?affiliate_id=rubel
// set affiliate id
var queryParts = new URLSearchParams(window.location.search);
var affiliate_id = queryParts.get('affiliate_id');
if(affiliate_id) {
@webhasan
webhasan / iframe-form.js
Last active November 7, 2023 12:34
iFrame From Tracking With GTM by Post Message
// iframe code
(function() {
var form = document.querySelector('form[action="FormConfirmation.aspx?sourceformid=41&formid=42"]');
if(form) {
var queryString = form.getAttribute('action');
form.addEventListener('submit', function (event) {
var formData = new FormData(this);
var userInputs = {};

Each section of the product should have class: gtm-item

In the title of the product or somewhere should have information (Change the value to right value)

class="gtm-item-title" data-gtm-product-id="4401.1" data-gtm-item-title="6-Hour 44547 CE Broker Responsibility Corr"

If there is two product together then use following instead top one (Change the value to right value)

class="gtm-item-title" data-gtm-multi="1" data-gtm-product-id="4102" data-gtm-product-id2="4401.1" data-gtm-item-title2="6-Hour 44547 CE Broker Responsibility Corr" data-gtm-item-title="SAE pkg I (98 Hour) Correspondence"

@webhasan
webhasan / youtube-video-tracking.js
Last active August 28, 2023 13:14
Elementor's Youtube Video Tracking with GTM (when nothing works)
(function () {
var videoProgress = [10, 25, 50, 75, 100];
var loadedIframes = [];
var intervalId;
window.dataLayer = window.dataLayer || [];
function handleIframe(iframe) {
if (/.+youtube.com\/embed.+/.test(iframe.src) && loadedIframes.indexOf(iframe) === -1) {
loadedIframes.push(iframe);
initializeVideoTracking(iframe);
@webhasan
webhasan / ads-click-dataLayer.js
Last active August 20, 2023 00:00
GTM Data Layer for Google AdSense Ads Click
(function() {
var isAdsArea = false;
var add_link = '';
var page_link = window.location.href;
document.addEventListener('mouseover', function (e) {
var target = e.target.closest('iframe[src^="https://googleads.g.doubleclick.net"]');
var target2 = e.target.closest('iframe[src$="/html/container.html"]');
if(target) {
@webhasan
webhasan / tinymce.init.js
Last active June 22, 2020 16:51
User WordPress tinymce including media uploader in JavaScript
// also need to enqueue script and style for tinymce
// by wp_enqueue_editor(); in php side
let {tinymce: tinymceObj, quicktags: quicktagsObj} = wp.editor.getDefaultSettings();
// textarea-id = id of the field
wp.editor.initialize('textarea-id', {
tinymce: {
...tinymceObj,
"toolbar1": "formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,wp_add_media,wp_adv",
"toolbar2": "strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help",
@webhasan
webhasan / nonce-fix.php
Created March 28, 2020 16:51
Nonce validation fix for logged out user with WooCommerce setuped
<?php
class My_Plugin {
public function hook() {
add_filter('nonce_user_logged_out', array($this, 'nonce_fix'), 100, 2);
}
public function nonce_fix($uid = 0, $action = ''){
$nonce_actions = array('pgfy-ajax-modal','pgfy-add-to-cart');