Skip to content

Instantly share code, notes, and snippets.

View anwari666's full-sized avatar

Anwari Ilman anwari666

  • Porto, Portugal
View GitHub Profile
@anwari666
anwari666 / code.sh
Created August 5, 2021 16:32
open vscode via command line in (mac)
ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code
@anwari666
anwari666 / fbEvent.gtm.js
Created August 6, 2018 12:14
[fbEvent] Construct the standard FB events #gtm #js #fb
/* Pixel events https://developers.facebook.com/docs/ads-for-websites/pixel-events/v3.1
* fbq('track/trackCustom', 'eventName', {customData});
* ViewContent / Search / AddToCart etc...
*/
// this
fbq( 'trackCustom', 'linkClick', {{getFBEventData}} );
@anwari666
anwari666 / fbpixel.html
Created August 6, 2018 12:09
[FB Pixel] Main FB Pixel tag #fb #gtm #js
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
@anwari666
anwari666 / getFBEventData.gtm.js
Created August 6, 2018 12:07
[getFBEventData] Construct FB Event Object #gtm #js #fb
/* build custom FB event data (object)
* and then return it
*/
function(){
return {
'content_category' : {{getLinkClickCategory}},
'content_name' : {{getLinkClickAction}},
'content_action' : {{getLinkClickAction}}, // I decided that `name` = `action` for consistency with GA events. and send the data anyway although it's duplicate
'content_label' : {{getClickUrlWithoutParam}}
};
@anwari666
anwari666 / pageDomainName.gtm.js
Last active August 17, 2018 21:24
[pageDomainName] Returns the main domain instead of the subdomain #gtm #js
// example "subdomain.ilman.co".match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/)
// will returns "ilman.co"
function()
{
return {{Page Hostname}}.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/)[0];
}
@anwari666
anwari666 / isOutboundClick.gtm.js
Created August 6, 2018 11:59
[isOutboundClick] checks whether a link is outbound. needs {{destinationHostame}} --> it's a Auto-Event variable > Element URL > Host Name. #gtm #js
function() {
if ({{destinationHostname}}.indexOf({{pageDomainName}}) === -1) {
return true;
}
return false;
@anwari666
anwari666 / getCleanUrlPath.gtm.js
Created August 6, 2018 11:56
[getCleanUrlPath] get a clean url without param. a.k.a removes URL part after '?' sign in a url. #gtm #js
// removes URL part after '?' sign in a url
function(){
return {{Click URL}}.split('?')[0];
}
@anwari666
anwari666 / getLinkClickAction.gtm.js
Last active August 17, 2018 21:20
[getLinkClickAction] #gtm #js
/* returns linkClickAction types. Possible values are:
* Online Booking
* Phone Call
* Internal Link
* destinationHostname (for outbound links)
*/
function(){
if ( {{destinationHostname}}.includes( {{Calendar Service Hostname}} ) )
{
@anwari666
anwari666 / getLinkClickCategory.gtm.js
Created August 6, 2018 11:53
[getLinkClickCategory] get possible link click categories. #gtm #js
/* Get possible link click categories. Return values are:
* Internal Link Click
* Outbound Link Click
* Contact Phone
*/
function(){
if ( {{isOutboundClick}} )
{
return 'Outbound Link Click';
@anwari666
anwari666 / setLocalStorage.js
Created August 3, 2018 21:23
[setLocalStorage] sets user's session/local storage. #gtm #js
/*
taken from http://dmitriilin.com/storages-cookies-in-google-tag-manager/
* Type – define the type of the storage you want to use, local or session.
* Name – name of the item
* Value – item’s value
USAGE
// create an item in sessionStorage
{{variable_name}}('session','item_name', 'item_value');