Giter VIP home page Giter VIP logo

Comments (3)

aawnu avatar aawnu commented on July 21, 2024 1

I am going to retag it dynamically so that people do not need to worry about it in existing projects and it should have no effect on your weight addition.

#77

from php-ga4.

aawnu avatar aawnu commented on July 21, 2024

Hello!

I am terribly sorry for the late reply; I saw it quickly on the phone and forgot all about it due to life... 👎🏼

I will load up a codespace and have a look.

from php-ga4.

mslepko avatar mslepko commented on July 21, 2024

No problem at all.

I've just inherited Item class in my project and added a few additional methods, including a custom item-scoped parameter “weight”.

final class Item extends \AlexWestergaard\PhpGa4\Item {
	protected null|string $weight;
	protected null|string $item_category2;
	protected null|string $item_category3;
	protected null|string $item_category4;
	protected null|string $item_category5;

	public function setWeight( string $weight ) {
		$this->weight = $weight;
		return $this;
	}

	public function addItemCategories( array $categories ) {
		$index = '';
		if ( count( $categories ) > 0 ) {
			foreach ( $categories as $category ) {
				$param                     = 'item_category' . $index;
				$this->$param              = $category;
				$index ? $index++ : $index = 2;
				// GA supports up to 5 categories.
				if ( $index >= 5 ) {
						break;
				}
			}
		}
		return $this;
	}

	public function getParams(): array {
		$params = parent::getParams();

		$custom_params = array(
			'item_category2',
			'item_category3',
			'item_category4',
			'item_category5',
			'weight',
		);

		return array_merge( $params, $custom_params );
	}
}

from php-ga4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.