0.5.4 • Published 2 days ago

@alexsab-ru/scripts v0.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@alexsab-ru/scripts

Русский

common libs for websites

Installation

pnpm i @alexsab-ru/scripts

Analytics module

reachGoal and pageView functions push to dataLayer some data with goal name

reachGoal("goalName");
pageView(goalName);

In GTM you can use them for send goals to your analytic system

{
	event: "reachGoal-goalName",
	eventAction: "goalName"
}

Use example:

import { reachGoal } from '@alexsab-ru/scripts';

// automatic assign from module
reachGoal("phone_click");
reachGoal("phone_copy");
reachGoal("phone_contextmenu");
reachGoal("email_click");
reachGoal("email_copy");
reachGoal("email_contextmenu");

For form's analytics you may use these goals

reachGoal("form_open");
reachGoal("form_click"); // automatic assign from module
reachGoal("form_change"); // automatic assign from module
reachGoal("form_submit");
reachGoal("form_required");
reachGoal("form_error");
reachGoal("form_success");

getFormDataObject is needed for Calltouch request tag.

import { getFormDataObject } from '@alexsab-ru/scripts';

document.querySelectorAll("form").forEach((form) => {
	form.onsubmit = async (event) => {

		var formData = new FormData(form);
		// ...
		var formDataObj = getFormDataObject(formData, form.id);

		await fetch("https://example.com/api/lead/", {
			// ...
		})
			.then((res) => res.json())
			.then((data) => {
				if (data.answer == "required") {
					reachGoal("form_required");
					return;
				} else if (data.answer == "error") {
					reachGoal("form_error");
					return;
				} else {
					reachGoal("form_success", formDataObj);
				}
				form.reset();
			})
			.catch((error) => {
				reachGoal("form_error");
			});
	};
});

Goals can be achieved as follows

Interaction with the form

  • form_open – opened the form
  • form_click – clicked on the form
  • form_change – changes in the form
  • form_submit – pressed the Submit button
  • form_required – incomplete form filling
  • form_error – error, data did not send for some reason
  • form_success – received a positive response from the server, i.e., data was sent
  • form_close – closed the form

Interaction with the phone

  • phone_click — clicked on it with the mouse
  • phone_contextmenu — opening the context menu on it with the right mouse button
  • phone_copy — copying the selected text

If there is a clickable email on the page, goals will be triggered on it

  • email_click — clicked on it with the mouse
  • email_contextmenu — opening the context menu on it with the right mouse button
  • email_copy — copying the selected text

Cookie module

import { getCookie, setCookie, deleteCookie, cookiecook } from './cookie';

getCookie('cookie_name');
setCookie('cookie_name');
deleteCookie('cookie_name');
cookiecook(days);

Calltouch module

import { createRequest } from '@alexsab-ru/scripts';

// Sending a callback request to CallTouch
createRequest("ct_callback", "+7 (987) 654-32-10");

// to display the log, the third parameter must be used
createRequest("ct_callback", "+7 (987) 654-32-10", true);

Form module

import { connectForms, cookiecook } from '@alexsab-ru/scripts';

cookiecook();
connectForms('https://alexsab.ru/lead/test/', function() {
	console.log("sucess lead");
});
0.5.4

2 days ago

0.5.3

4 days ago

0.5.2

3 months ago

0.5.0

3 months ago

0.5.1

3 months ago

0.4.5

3 months ago

0.4.4

3 months ago

0.4.3

4 months ago

0.4.2

4 months ago

0.4.1

5 months ago

0.4.0

5 months ago

0.3.1

5 months ago

0.1.0

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago