Friday, 31 March 2023

Meta Tracking

Mata Pixel

Using Mata Pixel, we can send tracking data to Facebook. There are two ways to send tracking data.

  • Javascript
  • Conversion API

Javascript method

You need pixel id and event name. The below is sample code to send a PageView event

<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');
  fbq('init', '{your-pixel-id-goes-here}');
  fbq('track', 'PageView');
</script>

There are two options to send event using Javascript

  • Emebed the above code snippet in the webpage
  • Run that code snippet directly. For example, for React page, we can run this Javascript code snippet directly using react hook useDidMountEffect

Test web browser events using the test events tool

  • Log into Facebook business account
  • Go to Events Manager
  • Click the Data sources icon on the middle side of the page
  • Click Test events
  • Find the browser events section
  • If do not see the browser events section, click clear event
  • Enter your website URL and click Open website. This opens your website in a separate window or tab
  • Do what you normally do to this website. Event will be recorded
  • Go back to Test Event section to check events recorded

Deduplication

If we send the same event using both conversion API and embedded javascript, Meta can use event id to deduplication. Meta will treat event with the same event id as the same event.

//use JS to send out event id
fbq('track', 'Purchase', {value: 12, currency: 'USD'}, {eventID: 'EVENT_ID'});

fbq('track', 'Lead', {}, {eventID: 'EVENT_ID'});

Specifications for Meta Pixel standard events

Developer Guide for Mata Pixel

Mata Conversion API

Coversion API Docs

React Tech Stack

Built in React Hook

Use Effect

Wednesday, 8 March 2023

Selenium

Install Selenium in Ubuntu

  1. pip install selenium
  2. download chrome webdriver Driver needs to match Chrome version installed in your machine
  3. unzip download files and copy chromedriver to /usr/bin folder
//hello_world.py
from selenium import webdriver

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://developer-leoshen.blogspot.com/2023/03/selenium.html")

driver.find_element_by_link_text("download chrome webdriver").click()

driver.find_element_by_id("age3").click()

firstName = driver.find_element_by_id("first_name").send_keys("leo")
python hello_world.py

PHP Selenium

//installation
1. down stand alone selenium server

2. install php library
compose require php-webdriver/webdriver ^1.13.1

3. install chrome driver
//test.php
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$host = 'http://localhost:4444/wd/hub';

$driver = Facebook\WebDriver\Remote\RemoteWebDriver::create($host, Facebook\WebDriver\Remote\DesiredCapabilities::chrome());

$driver->get("https://ca.yahoo.com");

$driver->manage()->window()->maximize();

$driver->quit();
//run standalone server
java -jar selenium-server-standalone-3.141.59.jar

//run test script
php test.php

The following is used for test script

Please select your age:






First Name :

Upgrade Chrome in my linux machine

sudo apt update
sudo apt upgrade

Thursday, 2 March 2023

AWS CLI Commands and profiles

multiple profiles in one machine

//who is calling
aws sts get-caller-identity

//list profiles
aws configure list-profiles

//add new profile for myone. set format: json default output format
//if does not add profile flag, the profile name is default
aws configure --profile myone

//use profile
aws sts get-caller-identity --profile myone

Some commands

# list lambda function
aws lambda list-functions

# overwrite default region
aws lambda list-functions --region us-west-1

Wednesday, 1 March 2023

postman

add variable in postman

  1. select environment such as local, sandbox
  2. select the environment quick look icon
  3. edit
  4. save

To use variable

{{api-key}}

See network info of a response

network icon is beside status:200 ok. can see remote ip etc