{"id":15162460,"url":"https://github.com/silverbackis/common-js-bundle","last_synced_at":"2026-02-23T09:02:43.539Z","repository":{"id":57075623,"uuid":"111843890","full_name":"silverbackis/common-js-bundle","owner":"silverbackis","description":"Include Google Analytics tracking codes and commonly used Javascript in your Symfony 3.4 / 4 application","archived":false,"fork":false,"pushed_at":"2017-12-11T09:52:38.000Z","size":238,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T03:53:26.267Z","etag":null,"topics":["google-analytics","js-sdk","symfony-bundle","twig"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silverbackis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-23T19:28:52.000Z","updated_at":"2017-11-29T18:11:12.000Z","dependencies_parsed_at":"2022-08-24T14:40:38.609Z","dependency_job_id":null,"html_url":"https://github.com/silverbackis/common-js-bundle","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverbackis%2Fcommon-js-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverbackis%2Fcommon-js-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverbackis%2Fcommon-js-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverbackis%2Fcommon-js-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silverbackis","download_url":"https://codeload.github.com/silverbackis/common-js-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247785922,"owners_count":20995643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-analytics","js-sdk","symfony-bundle","twig"],"created_at":"2024-09-27T01:43:40.220Z","updated_at":"2025-10-29T22:34:33.274Z","avatar_url":"https://github.com/silverbackis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Common JS Bundle\n***Not affiliated with The CommonJS group***\n\n[![Build Status](https://travis-ci.org/silverbackis/common-js-bundle.svg?branch=master)](https://travis-ci.org/silverbackis/common-js-bundle)\n[![codecov](https://codecov.io/gh/silverbackis/common-js-bundle/branch/master/graph/badge.svg)](https://codecov.io/gh/silverbackis/common-js-bundle)\n[![license](https://img.shields.io/github/license/silverbackis/common-js-bundle.svg)](LICENCE)\n\nThis bundle provides twig functions to easily add commonly used Javascript tags \u0026 SDKs to any page.\n\nBy default this bundle will support\n- Google Analytics\n- Google Tag Manager (GTM)\n- Facebook Javascript SDK\n- Twitter for Websites\n\n## Requirements\nThis bundle is only configured and tested to be used for Symfony \u003e=3.4\n\nAll default configurations and examples assume you are using Symfony Flex.\n\n## Installation\nThis bundle will be submitted to the Symfony Flex contrib repository shortly with some example configs. If you're using flex, the bundle will automatically be added into yor bundles.php file though.\n\nEnable the Symfony Flex Recipes Contrib Repository\n```bash\ncomposer config extra.symfony.allow-contrib true\n```\n\nUntil merged set the SYMFONY_ENDPOINT env var:\n```bash\nexport SYMFONY_ENDPOINT=https://symfony.sh/r/github.com/symfony/recipes-contrib/159\n```\n\nInstall the bundle:\n```bash\ncomposer req \"silverbackis/common-js-bundle:^1.0@beta\"\n```\n\nUntil merged, unset the environment variable:\n```bash\nunset SYMFONY_ENDPOINT\n```\n\n## Getting Started\n\n### Configuration\nThe default configuration values will work for 90% of use cases if you simply set the environment variables (when required). Other scripts will be enabled by default.\n\nHowever, you may wish to create a config file to add in default blocks:\n```yaml\n# config/packages/silverback_common_js.yaml\n# Enable and configure the scripts you'd like\nsilverback_common_js:\n    google_analytics:\n        default_blocks:\n            page_view: ~\n            \"ec/init\":\n                currency: USD\n```\n`default_blocks` can be an array of blocks you want. You can also include parameters if you want. It will pre-populate blocks in the order provided so you can just write `{{ cjs_js('name') }}` in your twig template\n\n\u003e You cannot pass the `default_blocks` variable in via the twig template, but you can still remove and modify the default blocks from the template using `cjs_add_block()` and `cjs_remove_block()` functions\n\nIdentifiers will be added as environment variables by Flex into your **.env** file.\n```dotenv\nGOOGLE_ANALYTICS_ID=\nGTM_CONTAINER_ID=\nFACEBOOK_APP_ID=\n```\nSet the IDs for these services if you want to enable them. Otherwise they will be disabled.\n\n### Example usage\nJavascript blocks can be configured directly from your twig templates using the following functions\n```twig\n{{ cjs_add_block(name, block_name, at_block_name, before_at_block_name, override_params_object) }}\n```\n\u003e`at_block_name` can be `\"false\"` (note this is a string) which will result in the function returning the javascript for you to insert. You may which to track a click event for example when a user clicks a link instead of in the main tracking code.\n\nYou can duplicate an SDK block including any blocks that have already been configured\n```twig\n{{ cjs_duplicate(name, block_name, override_params_object) }}\n```\n\nYou can also remove a block (e.g. if you've duplicated a block but want to remove a specific section )\n```twig\n{{ cjs_remove_block(name, block_name) }}\n```\n\nTo generate a new model to be inserted as a parameter you can use `cjs_model` - this example shows how you can create your model with arguments to define variables and/or using setters and then how you would inject the model as a parameter into a block.\n```twig\n{% set my_model = cjs_model(name, model, args_array) %}\n{{ my_model.setArg3('arg3') }}\n{{ cjs_add_block(name, block_name, null, false, { param_name: my_model }) }}\n```\n\nFinally to output the scripts **after** all the blocks have been configured for a given block use the `cjs_js` function\n```twig\n{{ cjs_js(name, override_params_object) }}\n```\n\nIf there is an noscript fallback specified, you will want to output this at a different section in your template. This is implemented when using GTM for example. Yuu can output the fallback HTML using `cjs_html`\n```twig\n{{ cjs_noscript(name, override_params_object) }}\n```\n\n### Models\nThere are models available for some SDK blocks (e.g. Google Analytics Event). You can use these to easily construct and pass data to a block. All models allow you to define all the variables in the constructor (in the order they are documented here) and also have getters and setters. Examples are provided in the individual script docs.\n\n### Supported Javascripts Docs\n#### [Google Analytics](Docs/GoogleAnalytics.md)\n#### [Google Tag Manager (GTM)](Docs/GoogleTagManager.md)\n#### [Twitter](Docs/Twitter.md)\n#### [Facebook SDK](Docs/FacebookSdk.md)\n\n### Contributing a new Javascript\nAdding an SDK is pretty straight forwards.\n- A new Provider is required in `CommonJsBundle\\Provider\\Sdk` extending `CommonJsBundle\\Provider\\BaseProvider`.\n- In the dependency injection new configuration parameters will be required\n- Models can be added in the `CommonJsBundle\\Model\\PascalCaseName` namespace where PascalCaseName is the name of the new javascript in PascalCase.\n- Template blocks are added in `Resources/views/blocks/snake_case_name` with an `init.html.twig` file and then a sub directory `js` for all blocks needed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverbackis%2Fcommon-js-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilverbackis%2Fcommon-js-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverbackis%2Fcommon-js-bundle/lists"}